Git undo仅在特定文件上自动合并,而不在整个分支上自动合并 [英] Git undo auto merging on a specific file only, not the whole branch

查看:92
本文介绍了Git undo仅在特定文件上自动合并,而不在整个分支上自动合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法撤消已更改的一个文件而不是Git中整个分支的自动合并?

Is there a way I can undo a auto-merge of one file that has been changed instead of the whole branch in Git?

我要撤消此合并:

自动合并public/stylesheets/application.css

Auto-merging public/stylesheets/application.css

恢复到以前的版本,其余版本保持当前状态.

to the previous version and leave the rest at its current state.

我尝试过:

git reset HEAD~1 public/stylesheet/application.css

但似乎不起作用.

推荐答案

当您这样做:

git reset HEAD~1 public/stylesheet/application.css

...将索引中文件的版本(即暂存版本)更改为HEAD~1中的版本-您的工作副本保持不变. 当前文档将其解释为:

... that changes the version of your file in the index (i.e. the staged version) to the version in HEAD~1 - your working copy remains the same. The current documentation explains this as:

此表单为所有< paths>重置索引条目.到< commit%>的状态. (它不会影响工作树,也不会影响当前分支.)

This form resets the index entries for all <paths> to their state at <commit%gt;. (It does not affect the working tree, nor the current branch.)

如果您这样做:

git checkout HEAD~1 -- public/stylesheet/application.css

...,这会将工作副本和暂存的版本都更改为HEAD~1的版本. --是为了安全起见,以防万一您拥有也可以理解为提交的文件名.

... that will change both the working copy and the staged version to the version from HEAD~1. The -- is there for safety, just in case you have file name that can also be understood as a commit.

现在已经进行了更改,可以使用以下命令修改合并提交:

Now that you're got that change staged, you could amend the merge commit with:

git commit --amend

...只要您没有将合并推送到任何地方,这是很公平的,因为合并仍然只是一个分支或另一个分支的更改.

... which is fair enough as long has you haven't pushed the merge anywhere, since the merge will still just have changes from one branch or the other.

这篇关于Git undo仅在特定文件上自动合并,而不在整个分支上自动合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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