1.基本常用命令
1 2 3 4 5 6 | git status #当前目录文件状态 git add #添加文件到 暂存空间 git commit #提交修改 # 分支 git branch -r #查看远程分支 git fetch origin --prune #更新远程分支 |
2.场景命令
1.如何自动保存远程仓库账号密码
Git可以将用户名,密码和仓库链接保存在硬盘中,而不用在每次push的时候都输入密码。
保存密码到硬盘一条命令就可以
$ git config credential.helper store
当git push
的时候输入一次用户名和密码就会被记录
参考
1 2 | $ man git | grep -C 5 password $ man git-credential-store |
这样保存的密码是明文的,保存在用户目录~的.git-credentials文件中
1 2 | $ file ~/.git-credentials $ cat ~/.git-credentials |
2.如何将分支feature上的提交复制到master
1 2 3 | #feature 上提交了3次,commit_id1,commit_id2,commit_id3 $ git checkout master #切换到master分支 $ git cherry-pick commit_id1 commit_id3 #两次提交之间没有merge操作,不然会无法完成 |
3.将本地代码推送到gitee
1 2 3 4 5 6 | $ git remote add origin xxx.git $ git config credential.helper store $ git pull origin master $ git add . $ git commit -m 'xx' $ git push origin master |