1

我从我们的 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)
4

1 回答 1

0

结果有人在两个不同的分支上创建了两次文件,没有合并(是的,已经发生了必要的公开鞭打),并且在一种情况下使用了所有大写字母,而在另一个分支上使用了所有小写字母。一旦他们意识到错误,他们删除了一个文件并合并,然后去度假。但他们从 Windows 中删除,不区分大小写。当他们进行合并时,它得到了两个副本。从假期回来后,他们在他们的分支上找不到文件,这导致弄清楚发生了什么。重新创建文件并合并后,一切都很好。

于 2012-08-16T15:44:16.670 回答