Reputation: 1435
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:
--force
parameter, same issuegit reset origin/master --hard
and running the pull
again, same issueHow can I update master
with another, more recent branch without caring for such issues, and while keeping its history?
Upvotes: 8
Views: 13138
Reputation: 1744
I came across this question because I had a similar issue. While the other answers already address possible fixes, I think I've found a cause.
In my situation, the conflict arose because of different file name case conventions. If you author the commits on a platform which has case-insensitive file names (Windows, macOS) and you change the case of the file name (whether intentionally or in my situation due to generated code), Git may use the new name in future commits but the O/S will not regard the file as having changed in any way, and Git seems to defer to the O/S on this matter.
This can result in bizarre situations, such as a file foo.txt
getting deleted by some commit even though it never existed in the first place, because the previous commit to touch it considered it to be called Foo.txt
instead. If you apply the commits in order on a case-insensitive platform, you won't see a problem. However, if you apply the commits in order on a case-sensitive platform (e.g., Linux), you will get the unable to unlink
error in the question. You can skip past the problem by hard resetting ahead to the new commit or cloning the repo fresh at its latest state, but the "bad" commits will still be in the history lurking.
This should probably be considered a bug in Git, even though it's not Git's fault per se, because it's too trusting of the O/S.
Upvotes: 0
Reputation: 1326994
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
Upvotes: 4
Reputation: 30408
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
Upvotes: 0