git merge “被我们删除了”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30746035/
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 "deleted by us"
提问by kris
I am doing a big merge.
A lot of files have been removed from the repo in my branch, and in doing the merge I want to keep this change for all of those files.
There are also some files that will need explicit merging and I'm intending to use git mergetool
to merge them.
我正在做一个大合并。许多文件已从我分支的 repo 中删除,在进行合并时,我想为所有这些文件保留此更改。还有一些文件需要显式合并,我打算git mergetool
用来合并它们。
I wish to keep the "deleted by us" change (ie. the files should remain deleted) for all deleted files. Other merge conflicts I want to resolve myself.
Is there a way I can tell git to keep the deleted files deleted?
我希望保留所有已删除文件的“由我们删除”更改(即文件应保持删除)。其他合并冲突我想自己解决。
有没有办法告诉 git 保留已删除的文件?
回答by Tim Biegeleisen
Here is a partial solution:
这是一个部分解决方案:
Resolve all non deleted merge conflicts by hand, which you have to do anyway
Type
git diff --name-only --diff-filter=U
to get a list of all remaining files in conflict. These files must be the ones you want deleted. Save the list of removed files asfilesToRemove.txt
Then do
cat filesToRemove.txt | xargs git rm
to remove all the files.
手动解决所有未删除的合并冲突,无论如何您都必须这样做
键入
git diff --name-only --diff-filter=U
以获取所有剩余冲突文件的列表。这些文件必须是您要删除的文件。将删除的文件列表另存为filesToRemove.txt
然后执行
cat filesToRemove.txt | xargs git rm
删除所有文件。
回答by Shubham Chaudhary
One linefix:
一行修复:
git diff --name-only --diff-filter=U | xargs git rm
回答by androidevil
You can resolve this by keeping the edited files by adding them back, and committing them once more:
您可以通过将编辑过的文件添加回来并再次提交来保留已编辑的文件来解决此问题:
git add .
or
或者
git add -A
Then commit
然后提交
git commit
If you want to resolve the confict by removing the files, you have to run git rm
instead of git add
.
如果要通过删除文件来解决冲突,则必须运行git rm
而不是git add
.
See: Resolving a merge conflict from the command line
请参阅:从命令行解决合并冲突
回答by Brian Davis
I also observed
我也观察到
abc.txt: needs merge
abc.txt:需要合并
when attempting
尝试时
git rm abc.txt
after cherry-picking and seeing the file in "deleted by us" status.
在挑选并看到处于“已被我们删除”状态的文件之后。
I ended up with a resolved delete by doing the following:
我通过执行以下操作最终解决了删除问题:
git add abc.txt
rm abc.txt
git add abc.txt
this adds abc.txt to the staging area (essentially recreating the "deleted by us" file. (which resolves the conflict status)
这会将 abc.txt 添加到暂存区(本质上是重新创建“被我们删除”文件。(解决冲突状态)
then deletes the files from the file system
然后从文件系统中删除文件
then adds to the stating area the fact that the file is now gone.
然后将文件现已消失的事实添加到说明区域。
there are probably shell tricks to run these 3 commands on your set of 1000+ files without much headache.
可能有 shell 技巧可以在您的 1000 多个文件集上运行这 3 个命令而不会很头疼。
there are probably better ways to handle this, but since git rm abc.txt
did not work as we expected for our situation(s) i thought i would share an alternative set of commands that seem to have worked without using the mergetool.
可能有更好的方法来处理这个问题,但是由于git rm abc.txt
在我们的情况下没有像我们预期的那样工作,我想我会分享一组替代命令,这些命令似乎在不使用mergetool 的情况下也能工作。
回答by kris
I'll leave the question - because I'm sure there is a good answer - this is what I have done in the mean time:
我会留下这个问题 - 因为我确信有一个很好的答案 - 这就是我在此期间所做的:
- Do
git status
to see the list of deleted files (1082) and the number that had merge conflicts (3) - In a text editor manually edit the 3 files that had merge conflicts, and then do
git add
on them - Create a text file with a line with the letter "d" on each line and nothing else for each of the (1082) files that had been deleted (d.txt)
- run
git mergetool < d.txt
- 执行
git status
查看已删除文件列表 (1082) 和发生合并冲突的数量 (3) - 在文本编辑器中手动编辑有合并冲突的 3 个文件,然后
git add
对它们进行处理 - 创建一个文本文件,每行带有字母“d”,对于已删除的每个(1082)文件(d.txt)没有其他内容
- 跑
git mergetool < d.txt
Not elegant, but faster than pressing the letter "d" and enter 1082 times
不优雅,但比按字母“d”输入1082次还快