swift - Xcode 6.3 中的 Git : Master branch showing new files from other branches in red and won't compile

标签 swift xcode git

我在使用 Xcode 的集成源代码管理和 Git 时遇到以下问题:

我有一个完美运行的 master 分支,我想开发两个新功能。所以我创建了两个新分支,我在每个分支上添加了一个新文件。

现在,当我切换回 master 分支或其他分支时,在提交更改并且没有 merge (我还不想 merge )之后,来自所有分支的文件出现在项目导航器中(那些不属于当前分支的是红色)并阻止我的代码编译,因为编译器提示这些文件不存在。

不管我在其他分支做了什么,我的主人至少应该编译吧?

我是否遗漏了一些微不足道的东西?

最佳答案

未跟踪的文件和未暂存的更改不属于任何分支。它们只存在于你的工作树中。当您切换分支时,这些文件/更改将保持不变。如果您希望它们只存在于某个分支中,则必须添加并提交所有它们。

这应该有助于理解:

$ 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

因此,如您所见,未暂存的更改会在切换分支时进行(这是设计使然)。当 checkout 另一个分支时,Git 会告诉您哪些文件包含更改(以 Modified 开头的行)。这也适用于未跟踪的文件(Git 无法删除它们,因为您可能需要它们),但在 checkout 分支时它们的名称不会明确输出。

要让 Git 在切换分支时删除文件,您必须先将它们添加(并提交!)到分支。

关于swift - Xcode 6.3 中的 Git : Master branch showing new files from other branches in red and won't compile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29706437/

相关文章:

swift - 如何展开双重可选?

带有十进制错误的Xcode数字键盘

iphone - 像foursquare或gowalla这样的应用程序是如何实现他们的签到功能的?

git - 在 Git 世界中切换到 master 分支时 'Checking out files' stat 表示什么?

ios - Peek 和 Pop 函数 SpriteKit

ios - 创建 UICollectionViewController 子类并添加为 subview Controller

iphone - 关于 UITableViewController Storyboard的建议

git - 计算 git 存储库之外的文件或目录的 git 哈希值

git - 在命令行中将 --no-color 设置为 git 的默认值

Swift:无法使用 Firebase 设置数据值