为什么我不能切换分支?

发布于 2024-11-07 05:47:04 字数 575 浏览 0 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

十秒萌定你 2024-11-14 05:47:04

如果您不想要 git status 中列出的任何合并,请尝试此操作:

git reset --merge

这会重置索引并更新工作树中 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:

git reset --merge

This resets the index and updates the files in the working tree that are different between <commit> and HEAD, 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

暮年 2024-11-14 05:47:04

如果合并产生冲突,您最终会在 git status 的输出中得到 both modded。在解决这些冲突之前,git 不会让您更改分支。如果您编辑该文件,您应该会在其中看到一些冲突标记 - 有一个 解决 git 手册中这些冲突的指南。 (由于 kernel.org 目前已关闭,您可以在此处找到该指南 相反。)

或者,如果您认为合并是一个错误,您可以使用以下命令撤消它:git reset --merge

You end up with both modified in the output of git 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

季末如歌 2024-11-14 05:47:04

如果你不关心 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}}

病毒体 2024-11-14 05:47:04

当我从远程更新新文件并且索引不正常时收到此消息。尝试修复索引,但通过 Xcode 4.5、GitHub.app (103) 和 GitX.app (0.7.1) 解析失败。所以,我这样做了:

git commit -a -m "your commit message here"

这可以绕过 git 索引。

帮助我了解 Git 和 Xcode 的两篇博客文章是:

  • Ray Wenderlich 在 Xcode 4.5 上
  • 2008 年的奥利弗·斯蒂尔

  • 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:

    git commit -a -m "your commit message here"
    

    which worked in bypassing the git index.

    Two blog posts that helped me understand about Git and Xcode are:

  • Ray Wenderlich on Xcode 4.5 and
  • Oliver Steele from 2008

  • 萌化 2024-11-14 05:47:04

    您可以使用 HEAD 重置分支

    git reset --hard branch_name
    

    ,然后获取分支并删除不在本地的远程分支,

    git fetch -p 
    

    you can reset your branch with HEAD

    git reset --hard branch_name
    

    then fetch branches and delete branches which are not on remote from local,

    git fetch -p 
    
    南街女流氓 2024-11-14 05:47:04

    在切换分支之前,您需要提交或销毁任何未保存的更改。

    如果切换分支意味着未保存的更改将被删除,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.

    瞳孔里扚悲伤 2024-11-14 05:47:04

    由于文件被两者修改,您需要添加它

    git add Whereami.xcodeproj/project.xcworkspace/xcuserdatauser.xcuserdatad/UserInterfaceState.xcuserstate
    

    或者如果您想忽略您的更改,那么

    git reset HEAD Whereami.xcodeproj/project.xcworkspace/xcuserdatauser.xcuserdatad/UserInterfaceState.xcuserstate
    

    在之后只需切换您的分支。这应该可以解决问题。

    Since the file is modified by both, Either you need to add it by

    git add Whereami.xcodeproj/project.xcworkspace/xcuserdatauser.xcuserdatad/UserInterfaceState.xcuserstate
    

    Or if you would like to ignore yoyr changes, then do

    git reset HEAD Whereami.xcodeproj/project.xcworkspace/xcuserdatauser.xcuserdatad/UserInterfaceState.xcuserstate
    

    After that just switch your branch.This should do the trick.

    谁与争疯 2024-11-14 05:47:04

    Git 表示您当前分支中存在未解决的合并冲突。理想情况下,您应该解决合并冲突,然后提交更改。

    但是,如果您真的不关心当前分支中的本地更改(也许您正在本地尝试某些内容,但不需要保留它们),

    git checkout -f <other-branch-name>
    

    如果您仍然想要第一个分支 ,您可以忽略并强制签出另一个分支(存在合并冲突)但只想从远程获取最新版本,您可以执行此

    • 操作 强制删除该分支
    • 新鲜签出分支
    # assuming you already switched to another branch
    
    git branch -D <branch-to-reset>
    git fetch
    git checkout <branch-to-reset>
    

    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

    git checkout -f <other-branch-name>
    

    IF you'd still want the first branch (with merge conflict) but just want the latest from remote, you can do this

    • Force delete that branch
    • Fresh checkout the branch
    # assuming you already switched to another branch
    
    git branch -D <branch-to-reset>
    git fetch
    git checkout <branch-to-reset>
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文