简体   繁体   English

撤消尚未推送的 Git 合并

[英]Undo a Git merge that hasn't been pushed yet

I accidentally ran git merge some_other_branch on my local master branch.我不小心在本地主分支上运行了git merge some_other_branch I haven't pushed the changes to origin master.我还没有将更改推送到原始主机。 How do I undo the merge?如何撤消合并?


After merging, git status says:合并后, git status说:

# On branch master
# Your branch is ahead of 'origin/master' by 5 commits.

How do I undo all these commits?我如何撤消所有这些提交?

With git reflog check which commit is one prior the merge ( git reflog will be a better option than git log ).使用git reflog检查哪个提交是合并之前的提交( git reflog将是比git log更好的选择)。 Then you can reset it using:然后您可以使用以下方法重置它:

git reset --hard commit_sha

There's also another way:还有另一种方式:

git reset --hard HEAD~1

It will get you back 1 commit.它会让你回到 1 次提交。

Be aware that any modified and uncommitted/unstashed files will be reset to their unmodified state .请注意,任何已修改和未提交/未存储的文件都将重置为未修改状态 To keep them either stash changes away or see --merge option below.为了让它们保持不变,要么隐藏更改,要么查看下面的--merge选项。


As @Velmont suggested below in his answer, in this direct case using:正如@Velmont 在他的回答中建议的那样,在这种直接情况下使用:

git reset --hard ORIG_HEAD

might yield better results, as it should preserve your changes.可能会产生更好的结果,因为它应该保留您的更改。 ORIG_HEAD will point to a commit directly before merge has occurred, so you don't have to hunt for it yourself. ORIG_HEAD将在合并发生之前直接指向提交,因此您不必自己寻找它。


A further tip is to use the --merge switch instead of --hard since it doesn't reset files unnecessarily:另一个技巧是使用--merge开关而不是--hard因为它不会不必要地重置文件:

git reset --merge ORIG_HEAD

--merge - 合并

Resets the index and updates the files in the working tree that are different between <commit> and HEAD, but keeps those which are different between the index and working tree (ie which have changes which have not been added).重置索引并更新工作树中 <commit> 和 HEAD 之间不同的文件,但保留索引和工作树之间不同的文件(即具有尚未添加的更改)。

Assuming your local master was not ahead of origin/master, you should be able to do假设您的本地主人没有领先于原产地/主人,您应该能够做到

git reset --hard origin/master

Then your local master branch should look identical to origin/master .然后您的本地master分支应该看起来与origin/master相同。

See chapter 4 in the Git book and the original post by Linus Torvalds .请参阅Git 书籍的第 4 章和Linus Torvalds 的原始帖子

To undo a merge that was already pushed :要撤消已推送的合并:

git revert -m 1 commit_hash

Be sure to revert the revert if you're committing the branch again, like Linus said.如果您再次提交分支,请务必恢复还原,就像 Linus 所说的那样。

It is strange that the simplest command was missing.奇怪的是缺少最简单的命令。 Most answers work, but undoing the merge you just did, this is the easy and safe way :大多数答案都有效,但撤消您刚刚所做的合并,这是一种简单而安全的方法

git reset --merge ORIG_HEAD

The ref ORIG_HEAD will point to the original commit from before the merge. ref ORIG_HEAD将指向合并之前的原始提交。

(The --merge option has nothing to do with the merge. It's just like git reset --hard ORIG_HEAD , but safer since it doesn't touch uncommitted changes.) --merge选项与合并无关。它就像git reset --hard ORIG_HEAD ,但更安全,因为它不会触及未提交的更改。)

With newer Git versions, if you have not committed the merge yet and you have a merge conflict , you can simply do:对于较新的 Git 版本,如果您尚未提交合并并且您有合并冲突,您可以简单地执行以下操作:

git merge --abort

From man git merge :man git merge

[This] can only be run after the merge has resulted in conflicts. [This] 只能在合并导致冲突后运行。 git merge --abort will abort the merge process and try to reconstruct the pre-merge state. git merge --abort将中止合并过程并尝试重建预合并状态。

You should reset to the previous commit.您应该重置为之前的提交。 This should work:这应该有效:

git reset --hard HEAD^

Or even HEAD^^ to revert that revert commit.甚至HEAD^^来还原该还原提交。 You can always give a full SHA reference if you're not sure how many steps back you should take.如果您不确定应该退后多少步,您可以随时提供完整的 SHA 参考。

In case when you have problems and your master branch didn't have any local changes, you can reset to origin/master .如果您遇到问题并且您的 master 分支没有任何本地更改,您可以重置为origin/master

Lately, I've been using git reflog to help with this.最近,我一直在使用git reflog来帮助解决这个问题。 This mostly only works if the merge JUST happened, and it was on your machine.这主要只在合并刚刚发生并且它在您的机器上时才有效。

git reflog might return something like: git reflog可能会返回如下内容:

fbb0c0f HEAD@{0}: commit (merge): Merge branch 'master' into my-branch
43b6032 HEAD@{1}: checkout: moving from master to my-branch
e3753a7 HEAD@{2}: rebase finished: returning to refs/heads/master
e3753a7 HEAD@{3}: pull --rebase: checkout e3753a71d92b032034dcb299d2df2edc09b5830e
b41ea52 HEAD@{4}: reset: moving to HEAD^
8400a0f HEAD@{5}: rebase: aborting

The first line indicates that a merge occurred.第一行表示发生了合并。 The 2nd line is the time before my merge.第二行是我合并之前的时间。 I simply git reset --hard 43b6032 to force this branch to track from before the merge, and carry-on.我只是git reset --hard 43b6032强制这个分支从合并之前开始跟踪,然后继续。

如果您正在合并,您可以随时中止它

git merge --abort

With modern Git, you can:使用现代 Git,您可以:

git merge --abort

Older syntax:旧语法:

git reset --merge

Old-school:老套:

git reset --hard

But actually, it is worth noticing that git merge --abort is only equivalent to git reset --merge given that MERGE_HEAD is present.但实际上,值得注意的是git merge --abort仅等效于git reset --merge ,因为MERGE_HEAD存在。 This can be read in the Git help for merge command.这可以在合并命令的 Git 帮助中阅读。

git merge --abort is equivalent to git reset --merge when MERGE_HEAD is present.

After a failed merge, when there is no MERGE_HEAD , the failed merge can be undone with git reset --merge , but not necessarily with git merge --abort , so they are not only old and new syntax for the same thing .合并失败后,当没有MERGE_HEAD时,可以使用git reset --merge撤消失败的合并,但不一定使用git merge --abort因此它们不仅是同一事物的旧语法和新语法

Personally I find git reset --merge much more powerful and useful in everyday work, so that's the one I always use.就我个人而言,我发现git reset --merge在日常工作中更加强大和有用,所以这是我一直使用的。

If branches are merged and not pushed, then git reset command given below will work to undo the merge:如果分支被合并而不被推送,那么下面给出的 git reset 命令将用于撤消合并:

git reset --merge ORIG_HEAD

Example:例子:

git reset --merge origin/master

Okay, the answers other people here gave me were close, but it didn't work.好的,这里其他人给我的答案很接近,但它不起作用。 Here's what I did.这就是我所做的。

Doing this...这样做...

git reset --hard HEAD^
git status

...gave me the following status. ...给了我以下状态。

# On branch master
# Your branch and 'origin/master' have diverged,
# and have 3 and 3 different commit(s) each, respectively.

I then had to type in the same git reset command several more times.然后我不得不多次输入相同的git reset命令。 Each time I did that, the message changed by one as you can see below.每次我这样做时,消息都会改变一个,如下所示。

> git reset --hard HEAD^
HEAD is now at [...truncated...]
> git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 3 and 3 different commit(s) each, respectively.
> git reset --hard HEAD^
HEAD is now at [...truncated...]
> git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 2 and 3 different commit(s) each, respectively.
> git reset --hard HEAD^
HEAD is now at [...truncated...]
> git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 1 and 3 different commit(s) each, respectively.
> git reset --hard HEAD^
HEAD is now at [...truncated...]
> git status
# On branch master
# Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded.

At this point, I saw the status message changed, so I tried doing a git pull , and that seemed to work:此时,我看到状态消息发生了变化,所以我尝试执行git pull ,这似乎有效:

> git pull
Updating 2df6af4..12bbd2f
Fast forward
 app/views/truncated |    9 ++++++---
 app/views/truncated |   13 +++++++++++++
 app/views/truncated |    2 +-
 3 files changed, 20 insertions(+), 4 deletions(-)
> git status
# On branch master

So long story short, my commands came down to this:长话短说,我的命令归结为:

git reset --hard HEAD^
git reset --hard HEAD^
git reset --hard HEAD^
git reset --hard HEAD^
git pull

You have to change your HEAD, Not yours of course but git HEAD....你必须改变你的 HEAD,当然不是你的,而是 git HEAD....

So before answering let's add some background, explaining what is this HEAD .所以在回答之前让我们添加一些背景知识,解释一下这个HEAD是什么。

First of all what is HEAD?

HEAD is simply a reference to the current commit (latest) on the current branch. HEAD只是对当前分支上当前提交(最新)的引用。
There can only be a single HEAD at any given time.在任何给定时间只能有一个HEAD (excluding git worktree ) (不包括git worktree

The content of HEAD is stored inside .git/HEAD and it contains the 40 bytes SHA-1 of the current commit. HEAD的内容存储在.git/HEAD中,它包含当前提交的 40 字节 SHA-1。


detached HEAD

If you are not on the latest commit - meaning that HEAD is pointing to a prior commit in history its called detached HEAD .如果您不是最新的提交——这意味着HEAD指向历史上的先前提交,它称为detached HEAD

在此处输入图像描述

On the command line, it will look like this- SHA-1 instead of the branch name since the HEAD is not pointing to the tip of the current branch在命令行上,它看起来像这样 - SHA-1 而不是分支名称,因为HEAD没有指向当前分支的尖端

在此处输入图像描述

在此处输入图像描述

A few options on how to recover from a detached HEAD:关于如何从分离的 HEAD 中恢复的一些选项:


git checkout

git checkout <commit_id>
git checkout -b <new branch> <commit_id>
git checkout HEAD~X // x is the number of commits t go back

This will checkout new branch pointing to the desired commit.这将签出指向所需提交的新分支。
This command will checkout to a given commit.此命令将检出给定的提交。
At this point, you can create a branch and start to work from this point on.此时,您可以创建一个分支并从这一点开始工作。

# Checkout a given commit. 
# Doing so will result in a `detached HEAD` which mean that the `HEAD`
# is not pointing to the latest so you will need to checkout branch
# in order to be able to update the code.
git checkout <commit-id>

# create a new branch forked to the given commit
git checkout -b <branch name>

git reflog

You can always use the reflog as well.您也可以随时使用reflog
git reflog will display any change which updated the HEAD and checking out the desired reflog entry will set the HEAD back to this commit. git reflog将显示更新HEAD的任何更改,并检查所需的 reflog 条目会将HEAD设置回此提交。

Every time the HEAD is modified there will be a new entry in the reflog每次修改 HEAD 时, reflog中都会有一个新条目

git reflog
git checkout HEAD@{...}

This will get you back to your desired commit这将使您回到所需的提交

在此处输入图像描述


git reset --hard <commit_id>

"Move" your HEAD back to the desired commit.将您的 HEAD “移动”回所需的提交。

# This will destroy any local modifications.
# Don't do it if you have uncommitted work you want to keep.
git reset --hard 0d1d7fc32

# Alternatively, if there's work to keep:
git stash
git reset --hard 0d1d7fc32
git stash pop
# This saves the modifications, then reapplies that patch after resetting.
# You could get merge conflicts if you've modified things which were
# changed since the commit you reset to.
  • Note: ( Since Git 2.7 )注意:( 从 Git 2.7 开始
    you can also use the git rebase --no-autostash as well.你也可以使用git rebase --no-autostash

git revert <sha-1>

"Undo" the given commit or commit range. “撤消”给定的提交或提交范围。
The reset command will "undo" any changes made in the given commit.重置命令将“撤消”在给定提交中所做的任何更改。
A new commit with the undo patch will be committed while the original commit will remain in the history as well.将提交带有撤消补丁的新提交,而原始提交也将保留在历史记录中。

# add new commit with the undo of the original one.
# the <sha-1> can be any commit(s) or commit range
git revert <sha-1>

This schema illustrates which command does what.这个模式说明了哪个命令做什么。
As you can see there reset && checkout modify the HEAD .如您所见, reset && checkout修改HEAD

在此处输入图像描述

It can be done multiple ways.它可以通过多种方式完成。

1) Abort Merge 1) 中止合并

If you are in-between a bad merge (mistakenly done with wrong branch), and wanted to avoid the merge to go back to the branch latest as below:如果您处于错误合并之间(错误地使用错误的分支完成),并且希望避免合并返回到最新的分支,如下所示:

git merge --abort

2) Reset HEAD to remote branch 2) 将 HEAD 重置为远程分支

If you are working from remote develop branch, you can reset HEAD to the last commit on remote branch as below:如果您在远程开发分支上工作,您可以将 HEAD 重置为远程分支上的最后一次提交,如下所示:

git reset --hard origin/develop

3) Delete current branch, and checkout again from the remote repository 3)删除当前分支,并再次从远程存储库中签出

Considering, you are working on develop branch in local repo, that syncs with remote/develop branch, you can do as below:考虑到,您正在本地仓库中开发与远程/开发分支同步的分支,您可以执行以下操作:

git checkout master 
##to delete one branch, you need to be on another branch, otherwise you will fall with the branch :) 

git branch -D develop
git checkout -b develop origin/develop

You could use git reflog to find the previous checkout.您可以使用git reflog查找以前的结帐。 Sometimes that's a good state you want to return back to.有时那是你想要回到的一个很好的状态。

Concretely,具体来说,

$ git reflog
$ git reset --hard HEAD@{0}

I was able to resolve this problem with a single command that doesn't involve looking up a commit id.我能够通过一个不涉及查找提交 ID 的命令来解决这个问题。

git reset --hard remotes/origin/HEAD

The accepted answer didn't work for me but this command achieved the results I was looking for.接受的答案对我不起作用,但这个命令达到了我想要的结果。

If you didn't commit it yet, you can only use如果你还没有提交,你只能使用

$ git checkout -f

It will undo the merge (and everything that you did).它将撤消合并(以及您所做的一切)。

Got to this question also looking to revert to match origin (ie, NO commits ahead of origin).遇到这个问题也希望恢复到匹配原点(即,在原点之前没有提交)。 Researching further, found there's a reset command for exactly that:进一步研究,发现有一个reset命令可以做到这一点:

git reset --hard @{u}

Note: @{u} is shorthand for origin/master .注意: @{u}origin/master的简写。 (And, of course, you need that remote repository for this to work.) (当然,您需要该远程存储库才能正常工作。)

The simplest answer is the one given by odinho - Velmont最简单的答案是 odinho - Velmont 给出的答案

First do git reset --merge ORIG_HEAD首先做git reset --merge ORIG_HEAD

For those looking to reset after changes are pushed, do this (Because this is the first post seen for any git reset merge questions)对于那些希望在推送更改后重置的人,请执行此操作(因为这是任何 git reset 合并问题的第一篇文章)

git push origin HEAD --force

This will reset in a way that you won't get the merged changes back again after pull.这将以一种在拉取后不会再次恢复合并更改的方式重置。

Answering the question " Undo a Git merge that hasn't been pushed yet "回答问题“撤消尚未推送的 Git 合并

You can use git reset --hard HEAD~1你可以使用git reset --hard HEAD~1

Consider the following situation where there are 2 branches master and feature-1 :考虑以下情况,其中有 2 个分支masterfeature-1


$ git log --graph --oneline --all

Do Git merge做 Git 合并

$ git merge feature-1

$ git log --graph --oneline --all

Undo Git merge撤消 Git 合并

$ git reset --hard HEAD~1

$ git log --graph --oneline --all

You can use only two commands to revert a merge or restart by a specific commit:您只能使用两个命令来恢复合并或通过特定提交重新启动:

  1. git reset --hard commitHash (you should use the commit that you want to restart, eg. 44a587491e32eafa1638aca7738) git reset --hard commitHash (你应该使用你想要重启的提交,例如 44a587491e32eafa1638aca7738)
  2. git push origin HEAD --force (Sending the new local master branch to origin/master) git push origin HEAD --force (将新的本地 master 分支发送到 origin/master)

Good luck and go ahead!祝你好运,继续前进!

Just for an extra option to look at, I've been mostly following the branching model described here: http://nvie.com/posts/a-successful-git-branching-model/ and as such have been merging with --no-ff (no fast forward) usually.只是为了看一个额外的选项,我一直在遵循这里描述的分支模型:http: //nvie.com/posts/a-successful-git-branching-model/并且因此已经与--no-ff (无快进)通常。

I just read this page as I'd accidentally merged a testing branch instead of my release branch with master for deploying (website, master is what is live).我刚刚阅读了这个页面,因为我不小心将一个测试分支而不是我的发布分支与用于部署的 master 合并(网站,master 是实时的)。 The testing branch has two other branches merged to it and totals about six commits.测试分支合并了另外两个分支,总共大约有六个提交。

So to revert the whole commit I just needed one git reset --hard HEAD^ and it reverted the whole merge.因此,要恢复整个提交,我只需要一个git reset --hard HEAD^并恢复整个合并。 Since the merges weren't fast forwarded the merge was a block and one step back is "branch not merged".由于合并没有快进,因此合并是一个块,后退一步是“分支未合并”。

If your merge and the corresponding commits were not pushed yet, you can always switch to another branch, delete the original one and re-create it.如果您的合并和相应的提交尚未推送,您可以随时切换到另一个分支,删除原始分支并重新创建它。

For example, I accidentally merged a develop branch into master and wanted to undo that.例如,我不小心将一个开发分支合并到 master 中并想撤消它。 Using the following steps:使用以下步骤:

git checkout develop
git branch -D master
git branch -t master origin/master

Voila!瞧! Master is at the same stage as origin, and your mis-merged state is erased. Master与origin处于同一阶段,并且您的错误合并状态被擦除。

If you want a command-line solution, I suggest to just go with MBO's answer.如果您想要一个命令行解决方案,我建议您只使用 MBO 的答案。

If you're a newbie, you might like the graphical approach:如果您是新手,您可能会喜欢图形方法:

  1. Kick off gitk (from the command line, or right click in file browser if you have that)启动gitk (从命令行,或在文件浏览器中右键单击(如果有))
  2. You can easily spot the merge commit there - the first node from the top with two parents您可以在那里轻松地发现合并提交 - 从顶部开始的第一个节点,有两个父节点
  3. Follow the link to the first/left parent (the one on your current branch before the merge, usually red for me)按照链接到第一个/左父级(合并前当前分支上的那个,对我来说通常是红色的)
  4. On the selected commit, right-click "Reset branch to here", pick the hard reset there在选定的提交上,右键单击“将分支重置到此处”,在此处选择硬重置

Strategy: Create a new branch from where everything was good.策略:创建一个新的分支,一切都很好。

Rationale: Reverting a merge is hard.理由:恢复合并很难。 There are too many solutions, depending on many factors such as whether you've committed or pushed your merge or if there were new commits since your merge.有太多的解决方案,这取决于许多因素,例如您是否已提交或推送您的合并,或者自合并后是否有新的提交。 Also you still need to have a relatively deep understanding of git to adapt these solutions to your case.此外,您仍然需要对 git 有比较深入的了解才能使这些解决方案适应您的情况。 If you blindly follow some instructions, you can end up with an "empty merge" where nothing will be merged, and further merge attempts will make Git tell you "Already up to date".如果你盲目地遵循一些说明,你最终可能会得到一个“空合并”,其中不会合并任何内容,进一步的合并尝试会让 Git 告诉你“已经是最新的”。

Solution:解决方案:

Let's say you want to merge dev into feature-1 .假设您想将dev合并到feature-1中。

  1. Find the revision that you want to receive the merge:找到要接收合并的修订:

     git log --oneline feature-1 a1b2c3d4 Merge branch 'dev' into 'feature-1' <-- the merge you want to undo e5f6g7h8 Fix NPE in the Zero Point Module <-- the one before the merge, you probably want this one
  2. Check it out (go back in time):检查一下(及时返回):

     git checkout e5f6g7h8
  3. Create a new branch from there and check it out:从那里创建一个新分支并检查它:

     git checkout -b feature-1

Now you can restart your merge:现在您可以重新开始合并:

  1. Merge: git merge dev合并: git merge dev

  2. Fix your merge conflicts.修复合并冲突。

  3. Commit: git commit提交: git commit

  4. When you're satisfied with the results, delete the old branch: git branch --delete feature-1当您对结果满意时,删除旧分支: git branch --delete feature-1

Just create new branch, then cherry-pick desired commits to it.只需创建新分支,然后挑选所需的提交给它。

Its saver and simpler then resets described in many answers above它的保护程序和简单的然后重置在上面的许多答案中描述

if no conflict and merge completed then:如果没有冲突和合并完成,则:

  git reset --hard HEAD~1

if while doing a merge got conflict then abort will take you out of the recent merge changes:如果在进行合并时发生冲突,则 abort 将使您退出最近的合并更改:

git merge --abort

I think you can do git rebase -i [hash] [branch_name] where [hash] is the identifying hash for however far back you want to rewind plus one (or however many commits back you want to go) and then delete the lines for the commits in the editor that you don't want any more.我认为您可以执行git rebase -i [hash] [branch_name]其中[hash]是标识哈希,无论您想倒退多远加一(或者无论您想返回多少次提交),然后删除行编辑器中您不再需要的提交。 Save the file.保存文件。 Exit.出口。 Pray.祈祷。 And it should be rewound.它应该被重绕。 You might have to do a git reset --hard , but it should be good at this point.您可能必须执行git reset --hard ,但此时应该很好。 You can also use this to pull specific commits out of a stack, if you don't want to keep them in your history, but that can leave your repository in a state that you probably don't want.如果您不想将它们保留在历史记录中,您也可以使用它从堆栈中提取特定提交,但这可能会使您的存储库处于您可能不想要的状态。

  1. First, make sure that you've committed everything.首先,确保你已经承诺了一切。

  2. Then reset your repository to the previous working state:然后将您的存储库重置为以前的工作状态:

     $ git reset f836e4c1fa51524658b9f026eb5efa24afaf3a36

    or using --hard ( this will remove all local, not committed changes! ):或使用--hard这将删除所有本地的,未提交的更改! ):

     $ git reset f836e4c1fa51524658b9f026eb5efa24afaf3a36 --hard

    Use the hash which was there before your wrongly merged commit.使用错误合并提交之前的哈希值。

  3. Check which commits you'd like to re-commit on the top of the previous correct version by:通过以下方式检查您想在先前正确版本的顶部重新提交哪些提交:

     $ git log 4c3e23f529b581c3cbe95350e84e66e3cb05704f commit 4c3e23f529b581c3cbe95350e84e66e3cb05704f ... commit 16b373a96b0a353f7454b141f7aa6f548c979d0a ...
  4. Apply your right commits on the top of the right version of your repository by:通过以下方式将正确的提交应用到存储库的正确版本的顶部:

    • By using cherry-pick (the changes introduced by some existing commits)通过使用cherry-pick(一些现有提交引入的更改)

       git cherry-pick ec59ab844cf504e462f011c8cc7e5667ebb2e9c7
    • Or by cherry-picking the range of commits by:或者通过以下方式挑选提交范围:

      • First checking the right changes before merging them:在合并它们之前首先检查正确的更改:

         git diff 5216b24822ea1c48069f648449997879bb49c070..4c3e23f529b581c3cbe95350e84e66e3cb05704f
      • First checking the right changes before merging them:在合并它们之前首先检查正确的更改:

         git cherry-pick 5216b24822ea1c48069f648449997879bb49c070..4c3e23f529b581c3cbe95350e84e66e3cb05704f

        where this is the range of the correct commits which you've committed (excluding wrongly committed merge).这是您已提交的正确提交的范围(不包括错误提交的合并)。

The simplest of the simplest chance, much simpler than anything said here:最简单的机会,比这里所说的要简单得多:

Remove your local branch (local, not remote) and pull it again.删除您的本地分支(本地,而不是远程)并再次拉取它。 This way you'll undo the changes on your master branch and anyone will be affected by the change you don't want to push.这样,您将撤消主分支上的更改,并且任何人都会受到您不想推送的更改的影响。 Start it over.重新开始。

If you committed the merge:如果您提交了合并:

git reset HEAD~1
# Make sure what you are reverting is in fact the merge files
git add .
git reset --hard
  1. git stash

  2. git branch -d the_local_branch

  3. git checkout -t <name of remote>

  4. git stash apply

这对我有用..!!

If you notice that you need to revert immediately after the merge and you haven't done anything else after the merge attempt, you can just issue this command: git reset --hard HEAD@{1} .如果您发现需要在合并后立即恢复并且在合并尝试后您没有做任何其他事情,您可以发出以下命令: git reset --hard HEAD@{1}

Essentially, your merge sha will be pointing to HEAD@{0} if nothing else was committed after the merge and so HEAD@{1} will be the previous point before the merge.本质上,如果合并后没有提交任何其他内容,您的合并sha将指向HEAD@{0} ,因此HEAD@{1}将是合并前的前一点。

In this case, you will want to reset your branch with git reset --hard <branch_name> .在这种情况下,您需要使用git reset --hard <branch_name>重置您的分支。 If you want to save your changes before reseting them be sure to create a new branch and git checkout <branch_name> .如果您想在重置之前保存更改,请确保创建一个新分支并git checkout <branch_name>

You can reset the state to a specific commit with git reset --hard <commit_id> as well.您也可以使用git reset --hard <commit_id>将状态重置为特定提交。

If the changes have been pushed you can use git revert <branch_name> instead.如果更改已被推送,您可以使用git revert <branch_name>代替。 Be sure to check out how to use git revert and git checkout in other scenarios as well.请务必查看如何在其他场景中使用git revert 和 git checkout

Use this command to abort a merge:使用此命令中止合并:

git merge --abort git 合并 --abort

You can use the git-reset command.您可以使用 git-reset 命令。

git-reset - Reset current HEAD to the git-reset - 将当前 HEAD 重置为

specified state.指定的状态。 git reset [--mixed | git reset [--混合 |

--soft | --软 | --hard | --硬 | --merge] [-q] [] git reset [-q] [] --merge] [-q] [] git 重置 [-q] []

[--] … git reset --patch [--] ... git reset --patch

[] [--] […] [] [--] […]

GIT-Reset GIT-重置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM