I am using Xcode's integrated Source Control with Git and I have the following problem:
我正在使用Xcode与Git的集成源代码控制,我有以下问题:
I have a perfectly working master branch and I want to work on two new features. So I create two new branches, where I add one new file at each branch.
我有一个完美的工作主分支,我想做两个新功能。我创建了两个新分支,在每个分支上添加一个新文件。
Now when I switch back to the master branch or the other branch, after committing the changes and without merging (I don't want to merge yet), the files from ALL the branches appear in the project navigator (the ones that don't belong to the current branch are in red colour) and prevent my code from compiling as the compiler complains that these files don't exist.
现在当我切换回主分支或分支,提交后更改并没有合并(我不想合并),文件从所有树枝出现在项目导航器(那些不属于当前分支在红色),阻止我的代码编译编译器抱怨这些文件不存在。
My master at least should compile regardless of what I've done in other branches right?
我的主人至少应该编译不管我在其他分支做了什么?
Am I missing something trivial here?
我是不是漏掉了什么?
1 个解决方案
#1
1
Untracked files and unstaged changes do not belong to any branch. They only live in your working tree. When you switch branches, those files/changes are left untouched. If you want them to exist only in a certain branch, you have to add and commit all of them.
未跟踪的文件和未分段的更改不属于任何分支。它们只生活在你的工作树上。当您切换分支时,这些文件/更改不会被修改。如果您希望它们仅存在于某个分支中,则必须添加并提交它们。
This should help understanding:
这将有助于理解:
$ git status
On branch master
nothing to commit, working directory clean
$ >>file echo 'added line'
$ touch new_file
$ git status
On branch master
Changes not staged for commit:
modified: file
Untracked files:
new_file
$ git checkout -b new_branch
M file
Switch to a new branch 'new_branch'
$ git status
On branch new_branch
Changes not staged for commit:
modified: file
Untracked files:
new_file
So, as you see, unstaged changes are carried over when switching branches (this is by design). When checking out another branch, Git tells you which files contain changes (the line starting with M
odified). This also holds for untracked files (Git cannot delete them, since you might need them), but their names are not explicitely output when checking out a branch.
因此,正如您所看到的,在切换分支时进行非分阶段的更改(这是设计的)。在检出另一个分支时,Git告诉您哪些文件包含更改(以修改开头的行)。这也适用于未跟踪的文件(Git不能删除它们,因为您可能需要它们),但是在检出分支时,它们的名称不是显式输出。
To have Git delete files when switching a branch, you have to add (and commit!) them to a branch first.
要使Git在切换分支时删除文件,您必须首先将它们添加到分支(并提交!)
#1
1
Untracked files and unstaged changes do not belong to any branch. They only live in your working tree. When you switch branches, those files/changes are left untouched. If you want them to exist only in a certain branch, you have to add and commit all of them.
未跟踪的文件和未分段的更改不属于任何分支。它们只生活在你的工作树上。当您切换分支时,这些文件/更改不会被修改。如果您希望它们仅存在于某个分支中,则必须添加并提交它们。
This should help understanding:
这将有助于理解:
$ git status
On branch master
nothing to commit, working directory clean
$ >>file echo 'added line'
$ touch new_file
$ git status
On branch master
Changes not staged for commit:
modified: file
Untracked files:
new_file
$ git checkout -b new_branch
M file
Switch to a new branch 'new_branch'
$ git status
On branch new_branch
Changes not staged for commit:
modified: file
Untracked files:
new_file
So, as you see, unstaged changes are carried over when switching branches (this is by design). When checking out another branch, Git tells you which files contain changes (the line starting with M
odified). This also holds for untracked files (Git cannot delete them, since you might need them), but their names are not explicitely output when checking out a branch.
因此,正如您所看到的,在切换分支时进行非分阶段的更改(这是设计的)。在检出另一个分支时,Git告诉您哪些文件包含更改(以修改开头的行)。这也适用于未跟踪的文件(Git不能删除它们,因为您可能需要它们),但是在检出分支时,它们的名称不是显式输出。
To have Git delete files when switching a branch, you have to add (and commit!) them to a branch first.
要使Git在切换分支时删除文件,您必须首先将它们添加到分支(并提交!)