2015-10-20 35 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