git

++++++++++++++++++++++++++++++++
GIT 学习手册
http://www.ihref.com/read-16369.html
1,Linux生成SSH密钥:ssh-keygen,创建rsa公钥,github设置写入id_rsa.pub
ssh-keygen -t rsa -C "name@email.com"
mac:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
位置: ~/.ssh/id_rsa.pub
测试验证是否成功:ssh -T git@github.com
2,设置账户
git config --global user.name "username" //设置用户名 git config --global user.email "lokidri@outlook.com" //设置邮箱
3,同步
- 若是已有某文件夹已经同步过github了,之后往里面新增了文件,想要把它添加到github的库中,只需要三步即可:
-
- git add
- git commit -m “XXX”
- git push -u origin master
-
- 新建仓库完整过程: .
-
- cd到上传的文件夹内
- 先新建本地仓库:
git init - 添加文件到本地仓库:git add .
- 提交到本地库并备注,此时变更仍在本地:git commit -m “First commit”
- git remote add origin https://github.com/XX/xx.git #本地与远程服务器关联(需要先在github上创建仓库)
- git push -u origin master
-
- 或者是先在本地创建仓库,再登录,与服务器建立认证协议。
cd myrepo
git add .
git commit -a
git push origin master //使用用户名和密码
// 或者使用ssh
ssh-keygen -t rsa -C "myemail@email.com"
// rsa粘贴到github setting // The git remote set-url command changes an existing remote repository URL.
git remote set-url origin git@github.com:myusername/myrepo.git
4,创建和合并分支
#显示当前分支类别 git branch #创建新分支 git branch new-feature #切换到新分支 git checkout new-feature git add #commit -a = add + commit git commit -a -m"mark" git push origin new-feature #合并进master git checkout master git merge new-feature git branch git push
----------------------------------
问题:
1. 怎么修改Git remote add时使用的远程仓库?
- 1. 修改命令
- git remote set-url origin URL
- 2.先删后加
- git remote rm origin
- git remote add origin git@github.com:xxx/xxx.git
- 3. 直接修改config文件
2. error:src refspec master does not match any
原因: 本地版本库为空, 空目录不能提交 (只进行了init, 没有add和commit就直接push)
+++++++++++++++++++++++++++++++++++++++++
pycharm中使用git
VCS>update project
update type: Merge\Rebase\Branch Default
Merge:
git stash: 备份当前的工作区的内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致。同时,将当前的工作区内容保存到Git栈中
git shelve doesn't exist in Git.
Only git stash:
when you want to record the current state of the working directory and the index, but want to go back to a clean working directory.
which saves your local modifications away and reverts the working directory to match the HEAD commit.

浙公网安备 33010602011771号