Git未合并的路径问题

ker*_*lin 71 git merge

我将分支狗合并为动物.当我去提交时,我得到以下内容:

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
Run Code Online (Sandbox Code Playgroud)

总而言之,我在每个分支中都有不同的目录名和文件名.动物分支有我想要的变化.

当我重置头部时,它不起作用.当我去采取任何其他git动作(删除,结帐等)时,我得到一个路径未找到错误.

我需要执行哪些命令?

Cas*_*bel 72

你需要做的就是:

# 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
Run Code Online (Sandbox Code Playgroud)

  • 进一步的解释会派上用场 (16认同)
  • 如果您只是想退出合并模式而不解决任何问题,那么另一个答案中提到的“git reset”是一个更好的选择。 (2认同)

nau*_*101 40

如果您的文件已经签入,并且您的文件已合并(但未提交,因此将合并冲突插入文件),则处理此情况的另一种方法是运行:

git reset
Run Code Online (Sandbox Code Playgroud)

这将切换到HEAD,并告诉git忘记任何合并冲突,并保持工作目录不变.然后,您可以编辑有问题的文件(搜索"更新的上游"通知).一旦处理完冲突,就可以运行了

git add -p
Run Code Online (Sandbox Code Playgroud)

这将允许您以交互方式选择要添加到索引的更改.一旦索引看起来很好(git diff --cached),你可以提交,然后

git reset --hard
Run Code Online (Sandbox Code Playgroud)

销毁工作目录中所有不需要的更改.

  • @takias:每个文件中的标记看起来像:`<<<<<<< [branch] \n [content] \n ==== \n [content] \n [分支] >>>>>> >`.我认为自从我写这篇文章后,格式可能略有不同,但请参阅https://wincent.com/wiki/Git_merge_conflict_cheatsheet作为示例. (2认同)