【问题标题】:Undo several commits in git which have not pushed to remote [duplicate]撤消 git 中尚未推送到远程的几个提交 [重复]
【发布时间】:2013-05-25 02:59:59
【问题描述】:

我已经运行了 git status 和

# On branch master
# Your branch is ahead of 'origin/master' by 4 commits.
#   (use "git push" to publish your local commits)
#
# 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:   app/views/layouts/_header.html.erb
#
no changes added to commit (use "git add" and/or "git commit -a")

我想在提交到我的远程存储库之前撤消所有 4 个提交和未暂存为提交的更改。我该怎么做?

【问题讨论】:

    标签: git github


    【解决方案1】:

    您还可以运行以下命令来重置遥控器的 HEAD:

    git reset --hard <REMOTE>/<BRANCH_NAME>
    

    例如:

    git reset --hard origin/master
    

    【讨论】:

      【解决方案2】:

      这将丢弃工作树中的所有本地更改和四个最新提交:

      git reset --hard HEAD~4
      

      【讨论】:

        猜你喜欢
        • 2020-01-18
        • 1970-01-01
        • 2011-08-22
        • 2020-06-12
        • 2011-01-24
        相关资源
        最近更新 更多