Git 合并冲突 - 远程文件已删除,本地文件已更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11648105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git Merge Conflict - Remote File Deleted, Local File Changed
提问by xylar
I merged in changes from another branch but I am getting conflicts because a file has been deleted on the remote branch but has changes on local branch.
我从另一个分支合并了更改,但由于远程分支上的文件已被删除但本地分支上有更改,因此出现冲突。
I would like to delete the file - I tried git rm path/to/file
but it says file: needs merge
. What is the best way of removing the file and committing the merge?
我想删除该文件 - 我试过了,git rm path/to/file
但它说file: needs merge
. 删除文件并提交合并的最佳方法是什么?
回答by fork0
Try using the --force
parameter:
尝试使用--force
参数:
git rm --force <file>
If you want to keep the file in filesystem:
如果要将文件保留在文件系统中:
git rm --cached <file>
回答by VonC
I tried
git rm path/to/file
but it says file:needs merge
我试过了,
git rm path/to/file
但它说文件:needs merge
You will no longer see that error message with Git 2.23 (Q3 0219, seven years later)
您将不再看到 Git 2.23(Q3 0219,七年后)的错误消息
"git rm
" resolving a conflicted path used to leak an internal message
"needs merge
" before actually removing the path, which was confusing.
This has been corrected.
“ git rm
”needs merge
在实际删除路径之前解决用于泄漏内部消息的冲突路径“ ”,这令人困惑。
这已得到纠正。
See commit b2b1f61(17 Jul 2019) by Junio C Hamano (gitster
).
(Merged by Junio C Hamano -- gitster
--in commit 5e9d978, 25 Jul 2019)
请参阅Junio C Hamano()提交的 b2b1f61(2019 年 7 月 17 日)。(由Junio C Hamano合并-- --在提交 5e9d978 中,2019 年 7 月 25 日)gitster
gitster
rm: resolving by removal is not a warning-worthy event
When resolving a conflict on a path in favor of removing it, using "
git rm
" on it is the standard way to do so.
The user however is greeted with a "needs merge
" message during that operation:$ git merge side-branch $ edit conflicted-path-1 $ git add conflicted-path-1 $ git rm conflicted-path-2 conflicted-path-2: needs merge rm 'conflicted-path-2'
The removal by "
git rm
" does get performed, but an uninitiated user may find it confusing:
"needs merge
? So I need to resolve conflict before being able to remove it???"The message is coming from "
update-index --refresh
" that is called internally to make sure "git rm
" knows which paths are clean and which paths are dirty, in order to prevent removal of paths modified relative to the index without the "-f
" option.We somehow ended up not squelching this message which seeped through to the UI surface.
Use the same mechanism used by "
git commit
", "git describe
", etc. to squelch the message.
rm:通过删除来解决不是一个值得警告的事件
当解决路径上的冲突以支持删除它时,
git rm
在它上面使用“ ”是这样做的标准方法。
然而,needs merge
在该操作期间,用户会收到一条“ ”消息:$ git merge side-branch $ edit conflicted-path-1 $ git add conflicted-path-1 $ git rm conflicted-path-2 conflicted-path-2: needs merge rm 'conflicted-path-2'
git rm
确实会执行由“ ”删除的操作,但未入门的用户可能会发现它令人困惑:
“needs merge
?所以我需要先解决冲突才能删除它???”该消息来自
update-index --refresh
内部调用的“ ”,以确保“git rm
”知道哪些路径是干净的,哪些路径是脏的,以防止删除相对于没有“-f
”选项的索引修改的路径。不知何故,我们最终没有压制这条渗透到 UI 表面的消息。
使用与“
git commit
”、“git describe
”等相同的机制来压制消息。