A way to reproduce the issue
is using a word file to cause the merge failure. Here's how to reproduce the issue:
create a repo a
:
mkdir a
cd a
git init
create a/alpha.docx
and save it, then continue with
git add alpha.docx
git commit -m "initial alpha commit"
Create a repo b
that has a
as remote:
cd ..
mkdir b
cd b
git clone ../a
Modify a/alpha.docx
and save it, then continue with
cd ../a
touch beta # create some file
git commit -am "modified alpha"
Open b/alpha.docx
in word and start typing something. Do not save it. This marks the file as busy.
cd ../b
git pull
This will create the file b/beta
, and then abort the merge with this error:
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /cygdrive/c/tmp2/b/../a
a797c43..5c6796e master -> origin/master
Updating a797c43..5c6796e
error: unable to unlink old 'alpha.docx': Device or resource busy
If you now try to pull again, after closing word and discarding your local changes, this happens:
$ git pull
Updating a797c43..5c6796e
error: The following untracked working tree files would be overwritten by merge:
beta
Please move or remove them before you merge.
Aborting
How to deal with this
Way 1
git reset --hard HEAD
git clean -f -d
git pull
as suggested here
Way 2
git add -A
git stash
git pull
git stash drop # optional
Why this is
I don't know. Feel encouraged to edit this section if you know it.
I, personally, would have expected git to remove all the new files when aborting the merge.
To quote Noufal Ibrahim's answer above:
A new commit with all the changes from the source branch is created in
the staging area. In case of a conflict, this process of updating the
staging area is interrupted and control is given to you. That's why
this happens.