Git:OS X上的分支问题

时间:2015-10-20 22:11:40

标签: git bash version-control

大家好我目前在git上面临着一个压力很大的问题。当我尝试修改一个特定的分支时,git也会在其他分支中保存更改。这些是我的终端记录:

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$

在我的swift文件中,如果我检查不同的分支没有任何反应,文件保持相同

1 个答案:

答案 0 :(得分: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