简体   繁体   中英

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

I'm pulling a branch into master in order to merge it.

Command I'm running is (while having master checked out): git pull origin feature/some_branch

Unfortunately it seems my colleagues have performed some (what I would think benign) file deletions on there, and now git spews out a error: unable to unlink old 'somefile': No such file or directory .

I've tried to look online but most of the references for this error concern permissions, which is not the case here.

The file in question is not present on master before the merge, while is it in the new branch.

The problem is that master wasn't updated in a long time so there are way too many changes and files affected for me to start figuring the code out.

I just need master to contain all the changes that came from the new branch. We never commit anything to master directly, always through merges.

What I've tried so far:

  • Using --force parameter, same issue
  • git reset origin/master --hard and running the pull again, same issue

How can I update master with another, more recent branch without caring for such issues, and while keeping its history?

I just need master to contain all the changes that came from the new branch.

Then you can force the merge, in order to reflect the content of that branch feature/some_branch .

But instead of using merge --ours master , you can use a similar idea , which preserve the first-parent history:

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

To replace your master branch with the version on origin/master , you could try deleting and recreating it. master is not required to be checked out while you do this, so you might be able to avoid errors relating to changing your working directory.

First check out a different branch that you are able to check out:

git checkout feature/some-branch

Then delete your local master branch and create it again, including its tracking information:

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

Finally, try switching to the new master :

git branch checkout master

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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