git stash
保存当前所有未提交的更改,特别是开发过程中在分支上代码还有很多没修改不想提交那么快,但是又要切换分支去改bug的时候,就可以用该命令保存当前更改,该命令有作用范围,默认是不会保存新添加的文件和.gitignore里面的文件的,可以和-u或者-a使用,一图说明stash保存范围:

git revert VS git reset

git revert

git reset

git reset 的三个参数
| working directory | staged snapshot | commit history | remark | |
| — soft | D | D | B | Difference between B and D was staged but not be commit |
| — mixed (default) | D | empty | B | Difference between B and D in working directory |
| — hard | B | empty | B | both working directory and staged snapshot are empty |
git merge VS git rebase

git merge
git checkout feature && git merge master feature
git rebase
git checkout feature && git rebase master
git rebase使用的黄金法则:
不要在任何公共分支使用git rebase,否则会扰乱别人的远程分支,只有在分支只有自己一个人提交代码的时候才可以用。
git-filter-repo
这个不是git的命令,这是一个Python写的工具,可以修改已提交commit的记录,特别是在公共仓库上发现提交了敏感信息,例如密码服务器地址等,就可以用该工具来修改已提交的记录。使用之前需要安装:
pip install git-filter-repo例如需要将所有包含有密码的commit都改掉:
git filter-repo --replace-text <(echo "password==>p455w0rd")或者把某个文件的所有commit都删掉:
git-filter-repo --path paasword.txt --invert-paths最后使用git push -f master origin 推送远程分支更改就可以了。