2

I've got a Git repository for my Android app that I'm trying to overhaul and I want to keep the current working version on hand. I've created a branch for the new development, and checked it out, but when switching to my old branch files that are specific to my new development show up.

My question is this: When you checkout a different branch, does Git delete all the local files from the current branch and then replace them with the new branch's local files? Or does Git just only modify local files when you checkout another branch? I'm using Windows if that makes a difference.

4

2 回答 2

1

您必须在存储库中为当前签出的分支添加并提交所有新文件,以便在切换到另一个分支时不会显示它们。

原因是 Git 会忽略尚未添加到其索引中的文件,并在切换分支时将它们安静地留在原处,以免被错误地删除。

于 2013-08-28T21:11:01.943 回答
1

如果您的工作目录很脏并且您不想仅仅为了更改分支而提交,则可以git stash在切换之前使用。

就像是:

git stash save "cool new feature; not ready for prime time"

一切都安全地存储在您的存储堆栈中(您可以存储不止一组更改),并且您的工作目录是干净的。

当您稍后切换回新的工作中分支时,您可以

git pop

假设您没有在两者之间藏匿任何其他东西,那么您又回到了原来的位置。

Git*Pro 书的第 6.3 节有更多关于这个主题的内容

于 2013-08-28T22:36:27.467 回答