git mergetool
来合并它们。我希望保留所有已删除文件的“deleted by us”更改(即这些文件应该保持删除状态)。对于其他合并冲突,我想自己解决。
是否有一种方法告诉git保留已删除的文件?
以下是部分解决方案:
手动解决所有未删除的合并冲突,这是必须做的。
键入 git diff --name-only --diff-filter=U
以获取所有剩余文件冲突的列表。这些文件必须是您想要删除的文件。将已删除文件的列表保存为 filesToRemove.txt
。
然后执行 cat filesToRemove.txt | xargs git rm
删除所有文件。
git diff --name-only --diff-filter=U | xargs git rm
。 - Ryan Pavlik一行代码解决:
git diff --name-only --diff-filter=U | xargs git rm
解释:
首先解决冲突的修改文件并将它们添加到暂存区,然后使用diff-filter
命令删除剩余未合并的文件。这里有文档(man git-diff
):
--diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected.
Also, these upper-case letters can be downcased to exclude. E.g. --diff-filter=ad excludes added and deleted paths.
Note that not all diffs can feature all types. For instance, diffs from the index to the working tree can never have Added entries (because the set of paths included in the diff is limited by what is in the index). Similarly, copied and renamed entries cannot appear if detection for those types is disabled.
yes d
的输出导入到git rm
中。 - Guncharsgit add .
git add -A
提交更改
git commit
git rm
而不是git add
。git status | grep 'deleted by us' | sed 's/deleted by us: //' | xargs git rm
git status
git status | grep 'deleted by us'
git status | grep 'deleted by us' | sed 's/deleted by us: //'
git status
、grep
、sed
和 xargs
的手册页。我会留下这个问题,因为我相信一定有一个好的答案,同时我也做了以下操作:
git status
命令,查看被删除的文件列表 (1082) 和那些产生合并冲突的文件数量 (3)git add
git mergetool < d.txt
虽然不够优雅,但比按下 "d" 键并回车 1082 次更快
我也注意到了
abc.txt:需要合并
在尝试时
git rm abc.txt
在挑选樱桃并看到文件处于“已被我们删除”的状态后。
我最终通过以下方式解决了删除的问题:
git add abc.txt
rm abc.txt
git add abc.txt
这将abc.txt添加到暂存区(实际上是重新创建了“被我们删除”的文件。(解决了冲突状态)
然后从文件系统中删除文件
然后将文件已经不存在的事实添加到暂存区。
可能有一些shell技巧可以在你的1000多个文件集上运行这3个命令而不会有太多麻烦。
可能有更好的处理方法,但由于git rm abc.txt
对我们的情况没有按预期工作,我想分享一组替代命令,似乎可以在不使用合并工具的情况下工作。
git rm
命令可以解决问题。 - Ambergit rm
已经完成了你想要的操作,你只需要提交结果即可。 - Amber