我显然根本不懂 git。这就是我得到的:
git branch (outputs that I'm on master)
git checkout -b foo
echo "next line" >> file (file is an existing file)
git add file (stages)
git checkout master
git status (shows that file has "next line" and is staged!!)
git commit (commits the changes that were staged on branch foo!!)
git checkout foo
这是踢球者。foo 现在不显示对工作目录或暂存中的文件所做的任何更改。
所以看起来 - 您所做的任何更改,包括修改文件和暂存,都发生在所有分支上。当您提交到特定分支时,这些更改将在所有其他分支上丢弃,除了您提交的分支。
这实际上是怎么回事?有人可以让我觉得这有意义吗?这听起来完全是古怪的行为,显然我没有得到让这成为明智之举的设计理念。
编辑明确的例子:
$ mkdir element
$ cd element
$ git init
Initialized empty Git repository in /home/dan/element/.git/
$ echo "one" >> one
$ git add one
$ git commit -m msg
[master (root-commit) 36dc8b0] msg
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 one
$ git checkout -b fire
Switched to a new branch 'fire'
$ echo "next line" >> one
$ git checkout master
M one
Switched to branch 'master'
$ cat one
one
next line
$
这显然与 git pro 书中的内容相矛盾:
This is an important point to remember: Git resets your working directory to look like the snapshot of the commit that the branch you check out points to. It adds, removes, and modifies files automatically to make sure your working copy is what the branch looked like on your last commit to it.