1.基本常用命令
git status #当前目录文件状态
git add #添加文件到 暂存空间
git commit #提交修改
# 分支
git branch -r #查看远程分支
git fetch origin --prune #更新远程分支
2.场景命令
1.如何自动保存远程仓库账号密码
Git可以将用户名,密码和仓库链接保存在硬盘中,而不用在每次push的时候都输入密码。
保存密码到硬盘一条命令就可以
$ git config credential.helper store
当git push
的时候输入一次用户名和密码就会被记录
参考
$ man git | grep -C 5 password
$ man git-credential-store
这样保存的密码是明文的,保存在用户目录~的.git-credentials文件中
$ file ~/.git-credentials
$ cat ~/.git-credentials
2.如何将分支feature上的提交复制到master
#feature 上提交了3次,commit_id1,commit_id2,commit_id3
$ git checkout master #切换到master分支
$ git cherry-pick commit_id1 commit_id3 #两次提交之间没有merge操作,不然会无法完成
3.将本地代码推送到gitee
$ 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
4.比较变更
我们经常要查看对工作目录的内容作了哪些修改,以确定这些修改是否合理。
$ git diff --cached // 查看将要提交的内容,这时候的比较的是:暂存区 vs HEAD
$ git diff // 当前你所做的,但是没有提交到暂存区的修改,也就是这时候比较:前工作目录 vs HEAD
$ git diff file // 比较单个文件
$ git diff commit1:path/file commit2:path/file // 比较不同提交中的同一个文件
$ git diff --stat // 查看统计信息