繁体   English   中英

Git Merge:错误:无法取消链接旧的<file>:没有这样的文件或目录

[英]Git Merge: error: unable to unlink old <file>: No such file or directory

我正在将一个分支拉成master以便合并它。

我正在运行的命令是(当master签出时): git pull origin feature/some_branch

不幸的是,似乎我的同事已经执行了一些(我认为是良性的)文件删除,现在git吐出error: unable to unlink old 'somefile': No such file or directory

我试图在线查看,但此错误的大多数参考都涉及权限,这不是这里的情况。

在合并之前,主文件中存在有问题的文件,而它在新分支中。

问题是master在很长一段时间内没有更新,因此有太多的更改和文件影响我开始计算代码。

我只需要master来包含来自新分支的所有更改。 我们永远不会直接master任何东西,总是通过合并。

到目前为止我尝试过的:

  • 使用--force参数,同样的问题
  • git reset origin/master --hard并再次运行pull ,同样的问题

如何更新master与另一个更近期的分支而不关心这些问题,并保持其历史记录?

我只需要master来包含来自新分支的所有更改。

然后,您可以强制合并,以反映该分支feature/some_branch

但是,您可以使用类似的想法来保留第一个父级历史记录,而不是使用merge --ours master

git checkout master

# make merge commit but without conflicts!!
# the contents of 'ours' will be discarded later
git merge -s ours feature/some_branch    

# make temporary branch to merged commit
git branch tmp         

# get contents of working tree and index to the one of feature/some_branch
git reset --hard feature/some_branch

# reset to our merged commit but 
# keep contents of working tree and index
git reset --soft tmp

# change the contents of the merged commit
# with the contents of feature/some_branch
git commit --amend

# get rid off our temporary branch
git branch -D tmp

# verify that the merge commit contains only contents of feature/some_branch
git diff HEAD feature/some_branch

要使用origin/master上的版本替换master分支,可以尝试删除并重新创建它。 在执行此操作时,不需要检出master ,因此您可以避免与更改工作目录相关的错误。

首先查看您可以查看的其他分支:

git checkout feature/some-branch

然后删除您的本地master分支并再次创建它,包括其跟踪信息:

git branch --delete master
git branch master origin/master
git branch --set-upstream-to=origin/master master

最后,尝试切换到新的master

git branch checkout master

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM