git Git未合并路径问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3207029/
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 unmerged path issue
提问by keruilin
I merged branch dog into animal. When I go to commit, I get the following:
我将分支狗合并为动物。当我去提交时,我得到以下信息:
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution
both deleted: ../public/images/originals/dog.ai
added by them: ../public/images/original_files/dog.ai
To make a long story short, I had different directory names and file names in each branch. Animal branch has the changes that I want.
长话短说,我在每个分支中有不同的目录名和文件名。动物分支有我想要的变化。
When I go to reset the head, it doesn't work. And when I go to take any other git action (remove, checkout, etc), I get a path not found error.
当我去重置头部时,它不起作用。当我执行任何其他 git 操作(删除、结帐等)时,出现路径未找到错误。
What commands do I need to execute?
我需要执行哪些命令?
采纳答案by Cascabel
All you should need to do is:
您需要做的就是:
# if the file in the right place isn't already checked in
git add <path to desired file>
# remove the "both deleted" file from the index
git rm --cached ../public/images/originals/dog.ai
git commit # commit the merge
回答by naught101
Another way of dealing with this situation if your files ARE already checked in, and your files have been merged (but not committed, so the merge conflicts are inserted into the file) is to run:
如果您的文件已经签入并且您的文件已经合并(但未提交,因此合并冲突被插入到文件中),另一种处理这种情况的方法是运行:
git reset
This will switch to HEAD, and tell git to forget any merge conflicts, and leave the working directory as is. Then you can edit the files in question (search for the "Updated upstream" notices). Once you've dealt with the conflicts, you can run
这将切换到 HEAD,并告诉 git 忘记任何合并冲突,并保持工作目录不变。然后您可以编辑有问题的文件(搜索“上游更新”通知)。处理完冲突后,您可以运行
git add -p
which will allow you to interactively select which changes you want to add to the index. Once the index looks good (git diff --cached
), you can commit, and then
这将允许您以交互方式选择要添加到索引的更改。一旦索引看起来不错(git diff --cached
),您就可以提交,然后
git reset --hard
to destroy all the unwanted changes in your working directory.
销毁工作目录中所有不需要的更改。