Git-撤消合并更改并重做合并

时间:2019-01-23 02:35:28

标签: git

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

git pull

有冲突:

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

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

2 个答案:

答案 0 :(得分:0)

您可以使用以下方式还原合并:

git revert -m <commit ID>

您还可以使用以下方法

您还可以通过其他方式执行此操作,方法是使用git reflog <branch>找出合并之前分支的位置,然后使用git reset --hard <commit_id>恢复旧的修订版(您将返回到此提交)。

然后就可以将其推回去。

应该很容易。

答案 1 :(得分:0)

Kunal的两个解决方案是合并有效且已提交时考虑的主要选项

另一方面,如果您尚未通过冲突后修复的提交完成合并,请按照您引用的git输出中的提示0

它将重置您的文件,使其处于合并命令之前的状态(此外,与还原相反,它不会使您的分支历史变得混乱)