这是两次检查的结果:为什么第二次检查失败了? 'git status' 显示一些文件已被修改,但我确定我没有触及这些文件。
praveensripati@MyMini:~/Hadoop/Git/hadoop-common$ git checkout branch-0.21
Switched to branch 'branch-0.21'
praveensripati@MyMini:~/Hadoop/Git/hadoop-common$ git checkout branch-0.20
error: The following untracked working tree files would be overwritten by checkout:
CHANGES.txt
LICENSE.txt
README.txt
bin/hadoop
bin/hadoop-daemon.sh
bin/hadoop-daemons.sh
Please move or remove them before you can switch branches.
Aborting
praveensripati@MyMini:~/Hadoop/Git/hadoop-common$ git status
# On branch trunk
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# CHANGES.txt
# LICENSE.txt
# README.txt
# bin/
# build.xml
# conf/
# lib/
# site/
# src/
nothing added to commit but untracked files present (use "git add" to track)
最佳答案
发生这种情况是因为您当前分支上未跟踪的部分或全部文件正在被您要更改到的分支跟踪。
例如,分支可能包含 CHANGES.txt。因为 git 不想覆盖你在工作区中的文件,如果给你这个错误允许你备份你在本地拥有的文件。您可以:
- 将这些文件移到安全的地方
- 如果您确定不需要这些文件,可以执行 checkout -f 切换到分支(这将覆盖所有冲突的文件)
存储不适用于当前分支上未跟踪的文件。您可以使用 git diff 来找出哪些文件在 0.20 上但不在 0.21 上。例如:
git diff --name-only branch-0.20
关于git - 为什么 'git checkout' 只对某些分支有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7552089/