Git结账到之前的分店,什么都不做,但为什么要上演?
Git checkout to a previous branch, do nothing, but why have something be staged?
我结帐到现有分支,什么都不做,然后想结帐到另一个现有分支。但它说:
xxx:~/OculusSDK/data$ git checkout AnotherExistingBranch
error: Your local changes to the following files would be overwritten by checkout:
.DS_Store
Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/UserInterfaceState.xcuserstate
Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
Please, commit your changes or stash them before you can switch branches.
Aborting
然后我做 'git status',它说:
xxx:~/OculusSDK/data$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
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: ../.DS_Store
modified: ../Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/UserInterfaceState.xcuserstate
modified: ../Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
no changes added to commit (use "git add" and/or "git commit -a")
为什么?谢谢。
我假设 XCode 同时是 运行。它将重新加载文件并写回磁盘。
.DS_Store 是 Mac OS 文件系统信息文件,您需要删除它,另外两个是 XCode.[= 中的设置文件10=]
通常,只是从一个分支签出并切换到另一个分支最多会导致合并。
我怀疑您正在签出的分支也有一个不同的 .gitignore
,它不包括您现在在您的状态中看到的那些文件类型。在过去的某个地方,您将这些文件添加到 git 存储库中。然后您将这些文件类型添加到 .gitignore 但可能没有从存储库中删除这些文件。 Git 然后感到困惑,因为它看到过去可能已经提交的文件,removed/ignored 通过 .gitignore 但现在又回来了,因为你不同的 .gitignore in这另一个分支。
为了避免这种状态,当我检测到我不应该提交(并且应该被忽略)的字段时,首先我将这些文件复制到一个新目录,然后我将它们从 Git 中删除(git rm
),然后我修改 .gitignore
以忽略这些文件类型并提交新的 .gitignore
。最后,我将这些文件移回原始目录。
我结帐到现有分支,什么都不做,然后想结帐到另一个现有分支。但它说:
xxx:~/OculusSDK/data$ git checkout AnotherExistingBranch
error: Your local changes to the following files would be overwritten by checkout:
.DS_Store
Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/UserInterfaceState.xcuserstate
Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
Please, commit your changes or stash them before you can switch branches.
Aborting
然后我做 'git status',它说:
xxx:~/OculusSDK/data$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
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: ../.DS_Store
modified: ../Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/UserInterfaceState.xcuserstate
modified: ../Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
no changes added to commit (use "git add" and/or "git commit -a")
为什么?谢谢。
我假设 XCode 同时是 运行。它将重新加载文件并写回磁盘。
.DS_Store 是 Mac OS 文件系统信息文件,您需要删除它,另外两个是 XCode.[= 中的设置文件10=]
通常,只是从一个分支签出并切换到另一个分支最多会导致合并。
我怀疑您正在签出的分支也有一个不同的 .gitignore
,它不包括您现在在您的状态中看到的那些文件类型。在过去的某个地方,您将这些文件添加到 git 存储库中。然后您将这些文件类型添加到 .gitignore 但可能没有从存储库中删除这些文件。 Git 然后感到困惑,因为它看到过去可能已经提交的文件,removed/ignored 通过 .gitignore 但现在又回来了,因为你不同的 .gitignore in这另一个分支。
为了避免这种状态,当我检测到我不应该提交(并且应该被忽略)的字段时,首先我将这些文件复制到一个新目录,然后我将它们从 Git 中删除(git rm
),然后我修改 .gitignore
以忽略这些文件类型并提交新的 .gitignore
。最后,我将这些文件移回原始目录。