git重写历史记录

1 修改上一次历史提交,替换掉上次的提交
git commit --amend

2 git rebase 将不同分支路径合并到同一分支路径上
eg:将master分支上的 conflic rebase合并到 head分支上
* ada88de(HEAD, test_rebase)Initial commit on test_rebase
| *2a4a11f (master) coflict rebase
| /
|/
* ac75384 This is a amend commit


$ git rebase master

1 如果发生冲突 可以执行git rebase --abort撤销
2 解决冲突 vim编辑冲突文件 ,
3 git rebase --continue,
4 git add 冲突文件,
5 git rebase --continue

结果:
* ada88de(HEAD, test_rebase)Initial commit on test_rebase
*2a4a11f (master) coflict rebase
|
|
* ac75384 This is a amend commit

如果像回到git rebase操作执行之前

git reflog查看所有head记录

使用git reset -- hard HEAD@{N} (N代表数字 )回到操作前的某一次提交

git reset --soft commit 只将版本库中的head指向commit
git reset --mixed commit 将版本库中的 head指向commit ,使用commit分支文件替换暂存去

git reset --hard commit 版本库指向commit ,替换了暂存去和工作区

原文地址:https://www.cnblogs.com/or2-/p/4943996.html