When I use git pull I get the "error: Updating the following directories would lose untracked files in it:" message.
I have two different repositories, which I'll call "good" and "abc". I'm trying to merge them into a parent repository following the procedure described here, in order to keep the original histories. This involves re-writing history with the help of git filter-branch, then pulling both repositories into a newly initialized parent repository. This is the failing step:
git pull abc/
remote: Counting objects: 237, done.
remote: Compressing objects: 100% (67/67), done.
remote: Total 237 (delta 129), reused 161 (delta 129)
Receiving objects: 100% (237/237), 54.99 KiB | 0 bytes/s, done.
Resolving deltas: 100% (129/129), done.
From abc
* branch HEAD -> FETCH_HEAD
error: Updating the following directories would lose untracked files in it:
abc/abc
Now, if I pull the "good" repository it works fine even after re-writing history. Or if I git pull abc before re-writing history, it also goes well. This seems to be specific to the "abc" repo combined with the filter-branch procedure. So the question is, what could possibly be wrong with this repository to cause this error? How do I go about troubleshooting it?
The full sequence of commands and output can be seen below:
:~$ mkdir gitexp
:~$ cd gitexp/
:~/gitexp$ git clone https://github.com/nagev/good
Cloning into 'good'...
remote: Counting objects: 770, done.
remote: Total 770 (delta 0), reused 0 (delta 0), pack-reused 770
Receiving objects: 100% (770/770), 3.84 MiB | 898.00 KiB/s, done.
Resolving deltas: 100% (301/301), done.
:~/gitexp$ git clone https://github.com/nagev/abc
Cloning into 'abc'...
remote: Counting objects: 199, done.
remote: Compressing objects: 100% (67/67), done.
remote: Total 199 (delta 129), reused 199 (delta 129), pack-reused 0
Receiving objects: 100% (199/199), 53.52 KiB | 0 bytes/s, done.
Resolving deltas: 100% (129/129), done.
:~/gitexp$ ls
good abc
:~/gitexp$ cd good/
:~/gitexp/good$ git filter-branch --index-filter 'git ls-files -s | sed "s-\t-&good/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
Rewrite 34f94b29c73edbb003f969136dba325a55df052d (43/60) (1 seconds passed, remaining 0 predicted)
Ref 'refs/heads/master' was rewritten
:~/gitexp/good$ cd ../abc/
:~/gitexp/abc$ git filter-branch --index-filter 'git ls-files -s | sed "s-\t-&abc/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
Rewrite e7ede9c143daa3d5188a4632a327dda75b1a4eaf (22/38) (1 seconds passed, remaining 0 predicted)
Ref 'refs/heads/master' was rewritten
:~/gitexp/abc$ cd ..
:~/gitexp$ git init
Initialized empty Git repository in /home/nagev/gitexp/.git/
:~/gitexp$ git pull abc/
remote: Counting objects: 237, done.
remote: Compressing objects: 100% (67/67), done.
remote: Total 237 (delta 129), reused 161 (delta 129)
Receiving objects: 100% (237/237), 54.99 KiB | 0 bytes/s, done.
Resolving deltas: 100% (129/129), done.
From abc
* branch HEAD -> FETCH_HEAD
error: Updating the following directories would lose untracked files in it:
abc/abc
Aborting
:~/gitexp$ cd abc/
:~/gitexp/abc$ tree
.
└── abc
├── vrct
├── jlsg.capnp
├── nabc
│ ├── forest.py
│ ├── info.py
│ ├── datalog.py
│ ├── rbsd.py
│ ├── rotation.py
│ ├── text.py
│ ├── __init__.py
│ ├── master.py
│ ├── structure.py
│ ├── calculate.py
│ └── date.py
├── abc
├── README.md
├── pao
│ ├── nah.py
│ ├── __init__.py
│ └── allow.py
├── setup.py
└── tests.py
3 directories, 20 files
:~/gitexp/abc$
I searched but answers like this didn't help. I'm using git 2.11.0. To be sure that the procedure for merging two repositories can be done on my system, I've experimented creating two empty repositories, "repo1" and "repo2", then merged both into a "super" repo. You can see the commands and output below.
:~$ mkdir super
:~$ cd super
:~/super$ git clone ~/repo1/
Cloning into 'repo1'...
done.
:~/super$ git clone ~/repo2
Cloning into 'repo2'...
done.
:~/super$ ls
repo1 repo2
:~/super$ cd repo1/
:~/super/repo1$ git filter-branch --index-filter 'git ls-files -s | sed "s-\t-&repo1/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
Rewrite 5c81fdf85fbd794efd4c52e339ed101c37400eb5 (1/1) (0 seconds passed, remaining 0 predicted)
Ref 'refs/heads/master' was rewritten
:~/super/repo1$ cd ../repo2
:~/super/repo2$ git filter-branch --index-filter 'git ls-files -s | sed "s-\t-&repo2/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
Rewrite 80b1ece2a855d173717c02e093182e236c3506be (1/1) (0 seconds passed, remaining 0 predicted)
Ref 'refs/heads/master' was rewritten
:~/super/repo2$ cd ..
:~/super$ git init
Initialized empty Git repository in /home/nagev/super/.git/
:~/super$ git pull repo1
remote: Counting objects: 4, done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From repo1
* branch HEAD -> FETCH_HEAD
:~/super$ rm -rf repo1/repo1
:~/super$ rm -rf repo1/.git/
:~/super$ git pull repo2 --allow-unrelated-histories
warning: no common commits
remote: Counting objects: 4, done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From repo2
* branch HEAD -> FETCH_HEAD
Merge made by the 'recursive' strategy.
repo2/file2 | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 repo2/file2
:~/super$ rm -rf repo2/repo2
:~/super$ rm -rf repo2/.git
:~/super$
:~/super$ tree
.
├── repo1
│ └── file1
└── repo2
└── file2
2 directories, 2 files
:~/super$ git log
commit 05eaf17bf5d8fe8c3e7128ddbd00a220cedd0867
Merge: 2f5d0aa 301e92d
Author: Nagev <nagev>
Date: Tue Feb 21 15:14:34 2017 +0000
Merge repo2
commit 301e92d8eb97c1a8b6bdaded89a279a419042bb0
Author: Nagev <nagev>
Date: Tue Feb 21 15:10:47 2017 +0000
Add file Two
commit 2f5d0aa4d5104c7b88564bf3d13cc75cfbf9a119
Author: Nagev <nagev>
Date: Tue Feb 21 15:09:57 2017 +0000
Add File One
As you can see that works fine. Any idea what could possibly be messing up repo "abc"?