我对git真的很陌生,我一直在尝试理解为什么git为什么在我运行git checkout来在两个分支之间切换时,在另一个分支的一个分支中不断显示更改的内容。但是,我尝试然后使用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”以避免这种情况吗?