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