我對git分支行爲感到困惑。代碼更改是否應該在不同分支間持續存在?
我有這個混帳回購協議:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
我創建一個本地分支,像這樣:
$ git checkout -b foo
Switched to a new branch 'foo'
$ git branch
* foo
master
$ git status
On branch foo
nothing to commit, working tree clean
現在我改變README.md文件。
$ date >> README.md
$ git status
On branch foo
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
現在我跳回到我的主分支,像這樣:
$ git checkout master
M README.md
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
但是當我做了git的狀態我看到README.md文件已經從我的富分支的修改!我不應該看到README.md文件的未修改版本嗎?我在這裏做錯了什麼?
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
$ tail README.md
# README.md
-----------
Meanvoy is just an idea I had to replace envoy with facter and
a mean stack backend.
Fri Mar 17 13:43:04 PDT 2017
您沒有將自述文件提交到您的分支,也沒有將其分級。你需要在分支上加上'git add'和'git commit'來永久保存它。 –
啊!這確實有我正在尋找的效果。我只是不想在我的foo分支中做任何永久的事情。謝謝。 –