Git 学习进阶篇-重写历史记录

Git 重写历史记录涉及命令:#git commit -amend#git rebase#git reset git commit –ament如果刚进行提交操作,发现提交信息写错了,或者还需要几个文件一起提交,那么使用–amend命令可以重新提交。忘了添加某个文件,重新提交$ git lol -- stage.txt //当前提交信息* 3ee6f40
摘要由CSDN通过智能技术生成

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值