Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can I not switch branches?

Tags:

git

xcode4

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 
like image 652
lampShade Avatar asked May 14 '11 15:05

lampShade


People also ask

How do I force switch to another branch?

You can pass the -f or --force option with the git checkout command to force Git to switch branches, even if you have un-staged changes (in other words, the index of the working tree differs from HEAD ). Basically, it can be used to throw away local changes.

Can you switch branches without committing?

when you switch to a branch without committing changes in the old branch, git tries to merge the changes to the files in the new branch. If merging is done without any conflict, swithing branches will be successful and you can see the changes in the new branch.

Can you switch to a different branch?

You can use the git switch - command to undo any changes you make and return to your previous branch. If you instead want to keep your changes and continue from here, you can use git switch -c <new-branch-name> to create a new branch from this point.


1 Answers

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

like image 57
jitendrapurohit Avatar answered Oct 13 '22 06:10

jitendrapurohit