为什么我不能切换分支?
我正在尝试在 git 中切换分支,但收到此错误消息:
error: you need to resolve your current index first
I'm using git under xcode4
git status
# On branch DateCode
# Unmerged paths:
# (use "git reset HEAD <file>..." to unstage)
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both modified: Whereami.xcodeproj/project.xcworkspace/xcuserdatauser.xcuserdatad/UserInterfaceState.xcuserstate
#
no changes added to commit (use "git add" and/or "git commit -a")
Frappuccinos-MacBook-Pro:whereami
I'm trying to switch branches in git but I'm getting this error message:
error: you need to resolve your current index first
I'm using git under xcode4
git status
# On branch DateCode
# Unmerged paths:
# (use "git reset HEAD <file>..." to unstage)
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both modified: Whereami.xcodeproj/project.xcworkspace/xcuserdatauser.xcuserdatad/UserInterfaceState.xcuserstate
#
no changes added to commit (use "git add" and/or "git commit -a")
Frappuccinos-MacBook-Pro:whereami
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如果您不想要 git status 中列出的任何合并,请尝试此操作:
这会重置索引并更新工作树中
和HEAD< 之间不同的文件/code>,但保留索引和工作树之间不同的那些(即具有尚未添加的更改)。
如果
和索引之间存在不同的文件具有未暂存的更改 - 重置将中止。有关此的更多信息 - https://www.techpurohit.in/list-some-有用的 git 命令 &文档链接 - https://git-scm.com/docs/git-reset
Try this if you don't want any of the merges listed in git status:
This resets the index and updates the files in the working tree that are different between
<commit>
andHEAD
, but keeps those which are different between the index and working tree (i.e. which have changes which have not been added).If a file that is different between
<commit>
and the index has unstaged changes -- reset is aborted.More about this - https://www.techpurohit.in/list-some-useful-git-commands & Doc link - https://git-scm.com/docs/git-reset
如果合并产生冲突,您最终会在
git status
的输出中得到both modded
。在解决这些冲突之前,git 不会让您更改分支。如果您编辑该文件,您应该会在其中看到一些冲突标记 - 有一个 解决 git 手册中这些冲突的指南。 (由于 kernel.org 目前已关闭,您可以在此处找到该指南 相反。)或者,如果您认为合并是一个错误,您可以使用以下命令撤消它:
git reset --merge
You end up with
both modified
in the output ofgit status
if there were conflicts produced by a merge. git isn't letting you change branch until you've resolved these conflicts. If you edit that file, you should see some conflict markers in it - there's a guide to resolving those conflicts in the git manual. (Since kernel.org is currently down, you can find that guide here instead.)Alternatively, if you think the merge was a mistake, you could undo it with:
git reset --merge
如果你不关心 git 所说的未完成的更改,那么你可以进行强制签出。
git checkout -f {{在此处插入您的分支名称}}
If you don't care about the changes that git says are outstanding, then you can do a force checkout.
git checkout -f {{insert your branch name here}}
当我从远程更新新文件并且索引不正常时收到此消息。尝试修复索引,但通过 Xcode 4.5、GitHub.app (103) 和 GitX.app (0.7.1) 解析失败。所以,我这样做了:
这可以绕过 git 索引。
帮助我了解 Git 和 Xcode 的两篇博客文章是:
I got this message when updating new files from remote and index got out of whack. Tried to fix the index, but resolving via Xcode 4.5, GitHub.app (103), and GitX.app (0.7.1) failed. So, I did this:
which worked in bypassing the git index.
Two blog posts that helped me understand about Git and Xcode are:
您可以使用 HEAD 重置分支
,然后获取分支并删除不在本地的远程分支,
you can reset your branch with HEAD
then fetch branches and delete branches which are not on remote from local,
在切换分支之前,您需要提交或销毁任何未保存的更改。
如果切换分支意味着未保存的更改将被删除,Git 不会让您切换。
You need to commit or destroy any unsaved changes before you switch branch.
Git won't let you switch branch if it means unsaved changes would be removed.
由于文件被两者修改,您需要添加它
或者如果您想忽略您的更改,那么
在之后只需切换您的分支。这应该可以解决问题。
Since the file is modified by both, Either you need to add it by
Or if you would like to ignore yoyr changes, then do
After that just switch your branch.This should do the trick.
Git 表示您当前分支中存在未解决的合并冲突。理想情况下,您应该解决合并冲突,然后提交更改。
但是,如果您真的不关心当前分支中的本地更改(也许您正在本地尝试某些内容,但不需要保留它们),
如果您仍然想要第一个分支 ,您可以忽略并强制签出另一个分支(存在合并冲突)但只想从远程获取最新版本,您可以执行此
Git says you have unresolved merge conflicts in your current branch. Ideally you should resolve the merge conflicts, and then commit the changes.
BUT, IF you really don't care about the local changes in current branch (maybe you were trying out something locally, but need not persist them), you can ignore and force checkout the other branch
IF you'd still want the first branch (with merge conflict) but just want the latest from remote, you can do this