当我切换分支时,为什么git merge会自动更改?

Mad*_*bæk 0 git

我刚开始使用git进行分支,我对切换分支的行为感到有点困惑.遵循这些步骤:

git init
Initialized empty Git repository in /Users/mads/Desktop/testing/.git/

echo 'hello a' > a.txt
echo 'hello b' > b.txt
git add *.txt
git commit -m "Initial commit"
[master (root-commit) 1ab870f] Initial commit
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 a.txt
 create mode 100644 b.txt

git status
# On branch master
nothing to commit (working directory clean)

git branch new_feature
git checkout new_feature
Switched to branch 'new_feature'

ls
a.txt   b.txt

echo "hello c" > c.txt
git add c.txt 

echo "hello a, new version" > a.txt

git status
# On branch new_feature
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   c.txt
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   a.txt
#

git commit -m "Added new feature"

[new_feature 1ccda31] Added new feature
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 c.txt

git checkout master
M   a.txt
Switched to branch 'master'

cat a.txt 
hello a, new version
Run Code Online (Sandbox Code Playgroud)

为什么a.txt上的更改会在结帐时自动拉入主数据库?这不是'合并'的目的吗?我想在一个分支上工作然后切换到另一个分支将被隔离...

Dav*_*d Z 6

git add a.txt修改后你从未跑过.Git不会自动跟踪您对文件所做的更改,甚至也不会跟踪您已添加到存储库的文件.(例如,这与SVN不同)git add如果要对更改进行版本控制,则每次更改时都必须明确显示每个文件.

或者,您可以使用-a选项git commit,它将自动添加和提交对git已经跟踪的文件所做的任何更改.所以最接近的svn commitgit commit -a.