Git 重写历史记录
涉及命令:
#git commit -amend
#git rebase
#git reset
git commit –ament
如果刚进行提交操作,发现提交信息写错了,或者还需要几个文件一起提交,那么使用–amend命令可以重新提交。
忘了添加某个文件,重新提交
$ git lol -- stage.txt //当前提交信息
* 3ee6f40 (HEAD -> master) efive commit~
* d4df151 five
$ touch stage2.txt
$ git add . //git rm
$ git commit --amend
[master 6ba634c] two file to commit~
Date: Thu Nov 17 23:39:39 2016 +0800
2 files changed, 1 insertion(+)
create mode 100644 stage2.txt
$ git lol
* 6ba634c (HEAD -> master) two file to commit~ //重新提交,覆盖了3ee6f40提交
* d4df151 five
忘了删除某个文件,重新提交
$ touch a.text b.txt //添加两个文件
$ git add .
$ git commit -m 'test for git rm'
$ git lol //查看历史
* 2506ac0 (HEAD -> master) test for git rm
* 50c430c delete a file
$ git rm b.txt //这时,发现b.txt不应该提交,需要删除
rm 'b.txt'
$ git commit --amend //重写历史,将暂存区内容作为提交的快照
[master bf8190a] test for git rm,and rm b.txt
Date: Sun Nov 20 20:57:20 2016 +0800
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.text
$ git lol //查看历史,可以看到记录已被修改
* bf8190a (HEAD -> master) test for git rm,and rm b.txt
* 50c430c delete a file
* ea9691e add file remove.d
$ ls //b.txt文件也已经被删除
a.text checkoutdi