【发布时间】:2011-04-03 17:55:02
【问题描述】:
我真的是 git 的新手,我一直试图理解为什么当我运行 git checkout 以在分支之间切换时,git 总是显示我在另一个分支的一个分支中所做的任何更改首先我尝试不使用 git add 并且没有不工作。但是,我尝试使用 git add,但没有解决问题。我还没有使用 git commit。
这基本上就是我正在做的事情:
$ git clone <a_repository>
$ git branch
* master
$ git branch testing
$ git checkout testing
...edit a file, add a new one, delete...
$ git status
# On branch testing
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: file1.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file2.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git branch
master
* testing
$ git checkout master
D file1.txt
Switched to branch 'master'
$ git status
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: file1.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file2.txt
no changes added to commit (use "git add" and/or "git commit -a")
我认为,在使用分支时,无论你在一个分支中做什么,它对所有其他分支都是不可见的。这不就是创建分支的原因吗?
我尝试使用“git add”,但更改在两个分支中都可见。 我是否需要在分支之间切换之前运行“git commit”以避免这种情况?
【问题讨论】:
标签: git