2015-10-20 47 views
-2

大家好我現在正面臨着git上的壓力問題。當我嘗試修改特定分支時,git也將更改保存在其他分支中。這些是我的終端記錄:Git:OS X上分支機構的問題

Pro-di-Mirko:gitfun mirko$ git status 
On branch master 
Changes to be committed: 
(use "git reset HEAD <file>..." to unstage) 
new file: .DS_Store 
modified: gitfun.swift 
Pro-di-Mirko:gitfun mirko$ git branch 
addingFunction 
master 
Pro-di-Mirko:gitfun mirko$ git checkout addingFunction 
A .DS_Store 
M gitfun.swift 
Switched to branch 'addingFunction' 
Pro-di-Mirko:gitfun mirko$ git status 
On branch addingFunction 
Changes to be committed: 
(use "git reset HEAD <file>..." to unstage) 
new file: .DS_Store 
modified: gitfun.swift 
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: gitfun.swift 
Pro-di-Mirko:gitfun mirko$ git add -A 
Pro-di-Mirko:gitfun mirko$ gi status 
-bash: gi: command not found 
Pro-di-Mirko:gitfun mirko$ git status 
On branch addingFunction 
Changes to be committed: 
(use "git reset HEAD <file>..." to unstage) 
new file: .DS_Store 
modified: gitfun.swift 
Pro-di-Mirko:gitfun mirko$ git branch 
addingFunction 
master 
Pro-di-Mirko:gitfun mirko$ git checkout master 
A .DS_Store 
M gitfun.swift 
Switched to branch 'master' 
Pro-di-Mirko:gitfun mirko$ git branch 
addingFunction 
master 
Pro-di-Mirko:gitfun mirkodevita$ 

在我迅速的文件,如果我籤不同的分支沒有任何反應,該文件保持一致

+2

看來你對'git add'有什麼誤解。這個階段文件將被提交給你當前所在的分支。所以你需要添加'git commit'來使它成爲分支的一部分。 – v01pe

回答

1

你從來沒有提交改變。

git add說「把這加到我的下一個承諾」。它把它放在一個叫做「暫存區」的地方。將所有更改添加到暫存區後,git commit將它們變成提交。

只有一個臨時區域。如果您查看其他分支,您仍將使用相同的分段區域。由於您只運行git add而不是git commit在分支之間切換會顯示相同的分階段更改。

Here's a good illustration of the staging area。而這describes the basic workflow and has a nice illustration of how data move around in Git