git pull产生“错误:在特定存储库

时间:2017-02-21 17:07:01

标签: git github merge pull

当我使用 git pull 时,我收到“错误:更新以下目录会丢失未跟踪的文件:”消息。

我有两个不同的存储库,我称之为“好”和“abc”。我正在尝试按照here描述的过程将它们合并到父存储库中,以保留原始历史记录。这涉及在 git filter-branch 的帮助下重写历史记录,然后将两个存储库拉入新初始化的父存储库。这是失败的步骤:

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

现在,如果我拉出“好”的存储库,即使在重写历史记录之后也能正常工作。或者,如果我在重写历史之前 git pull abc ,它也会顺利进行。这似乎是特定于“abc”repo与filter-branch程序的结合。所以问题是,这个存储库导致此错误可能有什么问题?我该如何排除故障?

完整的命令和输出序列如下所示:

:~$ 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$ 

我搜索了但this之类的答案没有帮助。我正在使用git 2.11.0。为了确保合并两个存储库的过程可以在我的系统上完成,我已经尝试创建了两个空存储库,“repo1”和“repo2”,然后将它们合并为一个“超级”存储库。您可以在下面看到命令和输出。

:~$ 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

正如您所看到的那样正常。知道什么可能搞乱回购“abc”?

1 个答案:

答案 0 :(得分:2)

我在检查另一个分支时遇到此错误消息。这真是令人沮丧。

执行git clean -xdfn abc/abc

如果您可以删除所有列出的文件,请执行git clean -xdf abc/abc

现在看看是否能解决您的问题。

显然,git会忽略这些文件(根据gitignore),但拒绝覆盖/删除它们。