git笔记(reflog)

原文地址https://github.com/XanthusL/blog-gen


不熟悉git,差点翻车


一如既往,在项目中添加某特性后愉快地提交

git commit -m "Feature add: blablabla" -- a.go b.go c.go

git push前习惯性地git status
于是发现了漏网的:

On branch develop
Your branch is up-to-date with 'origin/develop'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   没打算提交.go
        modified:   忘了提交.go

no changes added to commit (use "git add" and/or "git commit -a")

漏了个文件而已,老司机肯定会顺手补上:

git commit --amend 忘了提交.go

然而渣渣哪会这种操作,那就reset再重新提交吧

git reset --keep 上一次的commitID

这时候我想要的git status结果是:

n branch develop
Your branch is up-to-date with 'origin/develop'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   没打算提交.go
        modified:   忘了提交.go
    modified:   a.go
    modified:   b.go
    modified:   c.go

no changes added to commit (use "git add" and/or "git commit -a")

其实是用错了reset的参数,如果用了mixed就是上面的结果
详情请参阅git help reset
由于用错了参数,看到的结果仍然是:

On branch develop
Your branch is up-to-date with 'origin/develop'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   没打算提交.go
        modified:   忘了提交.go

no changes added to commit (use "git add" and/or "git commit -a")

而且,刚刚提交的文件也变回了上次提交后的状态。也就是说上次提交的更改都丢了,反而对忘了提交.go的更改没有丢失
呵呵哒,吓得我键盘都飞出去了
于是仔(大)细(概)研(了)究(解)了一下git的机制。
果然,还是没找到办法
方了,彻底方了
。。。
。。。
google诚不我欺,无意间搜到了reflog


git reflog

cc976e6 HEAD@{0}: reset: moving to cc976e634a9c7bc81ebfa27668fe24bc6804c80d
c24d9b5 HEAD@{1}: commit: Feature add: blablabla

git reset --keep c24d9b5
最后git commit --amend 忘了提交.go

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值