更改分支似乎删除文件

时间:2012-07-27 15:52:34

标签: git

我从我们的git服务器克隆一个repo,然后签出一个跟踪的分支,然后是git status; git表示文件已被删除。在repo中没有工作,只有git命令按此顺序:

git clone <myrepo>
git branch - indicates on master branch
git status - reports working directory is clean
git checkout <release-branch>
git status - shows a file has been deleted

执行ls <file>失败,表示文件确实已删除。 gitk显示红色节点,指示本地未提交的更改,但没有在repo中进行任何更改,只是检查到分支。在gitk中查看树时,父提交具有该文件。 git checkout -- <file>将文件带回来。

但是,如果我克隆相同的仓库,但包含分支,然后执行状态,则该文件存在:

git clone -b <release-branch> <myrepo>
git status - reports working directory is clean
ls <file> - shows file exists

这可以由不同系统中的几个不同的人重复。

为什么更改分支会导致删除此文件?

这是完整的命令行序列和输出(名称已更改以保护无辜者):

$ rm -rf test-*

$ git clone <repo> test-master
Cloning into 'test-master'...
remote: Counting objects: 11478, done.
remote: Compressing objects: 100% (5918/5918), done.
remote: Total 11478 (delta 7856), reused 8429 (delta 5558)
Receiving objects: 100% (11478/11478), 7.48 MiB | 183 KiB/s, done.
Resolving deltas: 100% (7856/7856), done.

$ cd test-master

$ git branch
* master

$ git status
# On branch master
nothing to commit (working directory clean)

$ git checkout relbranch
Checking out files: 100% (112/112), done.
Branch relbranch set up to track remote branch relbranch from origin.
Switched to a new branch 'relbranch'

$ git status
# On branch relbranch
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    prtbatt.c
#
no changes added to commit (use "git add" and/or "git commit -a")

$ cd ..

$ git clone -b relbranch <repo> test-relbranch
Cloning into 'test-relbranch'...
remote: Counting objects: 11478, done.
remote: Compressing objects: 100% (5918/5918), done.
remote: Total 11478 (delta 7856), reused 8429 (delta 5558)
Receiving objects: 100% (11478/11478), 7.48 MiB | 178 KiB/s, done.
Resolving deltas: 100% (7856/7856), done.

$ cd test-relbranch

$ git branch
* relbranch

$ git status
# On branch relbranch
nothing to commit (working directory clean)

1 个答案:

答案 0 :(得分:0)

原来有人在两个不同的分支上创建了两次文件,没有合并(是必要的公共floggings),在一种情况下使用全部大写字母,在另一个分支上使用全部小写字母。一旦他们意识到错误,他们删除了一个文件并合并,然后去度假。但是他们从Windows中删除了,这不区分大小写。当他们合并时,它可以获得两份副本。从假期回来后,他们无法在他们的分支上找到该文件,这导致弄清楚发生了什么。重新创建文件并合并后,一切都很好。