Why can I not switch branches?

后端 未结 7 1047
故里飘歌
故里飘歌 2020-12-13 23:29

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 g

相关标签:
7条回答
  • 2020-12-13 23:55

    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

0 讨论(0)
  • 2020-12-14 00:02

    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.com/list-some-useful-git-commands & Doc link - https://git-scm.com/docs/git-reset

    0 讨论(0)
  • 2020-12-14 00:12

    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.

    0 讨论(0)
  • 2020-12-14 00:13

    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

    0 讨论(0)
  • 2020-12-14 00:13

    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 
    
    0 讨论(0)
  • 2020-12-14 00:14

    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.

    0 讨论(0)
  • 提交回复
    热议问题