首页 > 解决方案 > Git - 撤消合并更改并重做合并

问题描述

我从远程存储库中提取了一些更改:

git 拉

有冲突:

Auto-merging src/app/models/budget-date.ts
CONFLICT (content): Merge conflict in src/app/models/budget-date.ts
Auto-merging src/app/components/timeline/timeline.component.ts
CONFLICT (content): Merge conflict in src/app/components/timeline/timeline.component.ts
Auto-merging src/app/components/timeline-date/timeline-date.component.ts
CONFLICT (content): Merge conflict in src/app/components/timeline-date/timeline-date.component.ts
Auto-merging src/app/components/expenses-log/expenses-log.component.ts
CONFLICT (content): Merge conflict in src/app/components/expenses-log/expenses-log.component.ts
Automatic merge failed; fix conflicts and then commit the result.

我合并了冲突,但我不确定我是否正确合并了冲突,所以我想撤消所有更改并重做合并:

git status
On branch release-0.1
Your branch and 'origin/release-0.1' have diverged,
and have 1 and 2 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Changes to be committed:

        modified:   src/app/components/expenses-log/expenses-log.component.html
        modified:   src/app/components/expenses-log/expenses-log.component.scss
        modified:   src/app/services/timeline/timline.service.ts

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both modified:   src/app/components/expenses-log/expenses-log.component.ts
        both modified:   src/app/components/timeline-date/timeline-date.component.ts
        both modified:   src/app/components/timeline/timeline.component.ts
        both modified:   src/app/models/budget-date.ts

如何撤消更改并重做合并?

标签: git

解决方案


您可以通过以下方式恢复该合并:

git revert -m <commit ID>

您也可以使用以下方法

你可以用其他方式git reflog <branch>来找出你的分支在合并之前的位置,并git reset --hard <commit_id>恢复旧的修订版(你将回到这个提交)。

然后你可以把它推回去。

它应该很容易。


推荐阅读