Git分支无法按预期工作
我正在阅读本教程: 据我所知,本教程说,如果我在Git分支无法按预期工作,git,git-branch,Git,Git Branch,我正在阅读本教程: 据我所知,本教程说,如果我在分支A中进行一些更改,它不会影响其他分支 所以我正在测试这个: $ mkdir test $ cd test/ $ git init Initialized empty Git repository in /root/test/.git/ $ echo 'foo' > foo.txt $ ls foo.txt $ git add * $ git commit -m 'added foo.txt' [master (root-commit) 2
分支A
中进行一些更改,它不会影响其他分支
所以我正在测试这个:
$ mkdir test
$ cd test/
$ git init
Initialized empty Git repository in /root/test/.git/
$ echo 'foo' > foo.txt
$ ls
foo.txt
$ git add *
$ git commit -m 'added foo.txt'
[master (root-commit) 25f6eb7] added foo.txt
1 file changed, 1 insertion(+)
create mode 100644 foo.txt
$ git branch testing # created a new branch
$ git branch
* master
testing
# I am still in 'master' branch
$ echo 'bar' > bar.txt # Add a file to 'master' branch
$ ls
bar.txt foo.txt # makes sense, because we are in 'master'
$ git checkout testing # Let's go to 'testing' branch
Switched to branch 'testing'
$ git branch
master
* testing
# OK, we are in 'testing'
$ ls
bar.txt foo.txt # WHY??
所以,我更改了“master”分支,它影响了“testing”。这里有什么问题
PS:MyGit版本1.7.10.4切换分支时,未跟踪(未提交)的文件不会被触动。因此,在提交后所做的任何操作都不会受到分支更改的影响。切换分支时,不会触及未跟踪(未提交)的文件。因此,提交后所做的任何操作都不会受到分支更改的影响。
将文件添加到“主”分支
——这是假设开始出错的步骤
通过使用echo'bar'>bar.txt
命令创建文件,您不会将其添加到分支
你应该准备并承诺这样做
因此,如果你:
git add bar.txt
git commit -m "Added a new file"
在签出进行
测试之前,它将按照您的预期工作。向“主”分支添加一个文件
——这是您的假设开始出错的步骤
通过使用echo'bar'>bar.txt
命令创建文件,您不会将其添加到分支
你应该准备并承诺这样做
因此,如果你:
git add bar.txt
git commit -m "Added a new file"
在签出进行测试之前
,它将按照您的预期工作