扔掉git中的本地提交 [英] Throw away local commits in git

查看:99
本文介绍了扔掉git中的本地提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于一些糟糕的樱桃采摘,我的本地git存储库目前提交5个提交之前,并没有一个良好的状态。我希望摆脱所有这些提交并重新开始。



显然,删除我的工作目录并重新复制可以做到这一点,但似乎再次从github下载所有东西像过度使用,并没有很好地利用我的时间。



也许 git revert 是我需要的,但我不希望在原点(甚至是6)之前提交 10 ,即使它确实使代码本身恢复到正确的状态。我只是想假装从未发生的最后半小时。



是否有一个简单的命令可以做到这一点?这似乎是一个明显的用例,但我没有找到任何示例。






注意这个问题是特别是关于提交不是 about:




  • 未跟踪文件

  • 非持续更改

  • 暂存但未提交的更改 / div>

    如果您的超额提交只对您可见,您可以执行 git reset --hard origin /< branch_name> 以移回到

    执行 git revert 使提交移除旧的 提交的方式可以保持每个人的历史记录。


    Due to some bad cherry-picking, my local git repository is currently 5 commits ahead of the origin, and not in a good state. I want to get rid of all these commits and start over again.

    Obviously, deleting my working directory and re-cloning would do it, but downloading everything from github again seems like overkill, and not a good use of my time.

    Maybe git revert is what I need, but I don't want to end up 10 commits ahead of the origin (or even 6), even if it does get the code itself back to the right state. I just want to pretend the last half-hour never happened.

    Is there a simple command that will do this? It seems like an obvious use case, but I'm not finding any examples of it.


    Note that this question is specifically about commits, not about:

    • untracked files
    • unstaged changes
    • staged but uncommitted changes

    解决方案

    If your excess commits are only visible to you, you can just do git reset --hard origin/<branch_name> to move back to where the origin is.

    Doing a git revert makes new commits to remove old commits in a way that keeps everyone's history sane.

    这篇关于扔掉git中的本地提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆