简体   繁体   中英

Git: How do I return to the branch after fixing merge conflicts?

Sometimes I will get a merge conflict when I git merge . I'll get the error:

Automatic merge failed; fix conflicts and then commit the result.

That's fine, and I fix the conflicts.

The problem is, once this happens, I seem to get kicked out of the branch I'm working on. Doing a git branch just shows me as on the develop branch.

If I try to check out the branch I was just working on I get an error

Please, commit your changes or stash them before you can switch branches.

If I try to commit or stash I get the error:

You are not on the correct branch.

The only way I can break out of this is to use git reset --hard HEAD which of course means I loose all my work.

Would anyone know why this is happening and what I can do?

  1. git status to check your now status.

  2. git diff to confirm that you fix conflicts correctly.

  3. git add your files.

  4. git commit .

    do your other jobs...

The only way I can break out of this is to use git reset --hard HEAD which of course means I loose all my work.

You're doing it wrong: use git merge --abort or git reset --merge if you want quit the current merge in progress.

Or finish the current merge as described by kagv. There is no third option... git has encountered a conflict and requires you to solve it manually. So fix it or reset to stable.

Note: when git detects a conflict (during a merge, rebase or cherry-pick action) you end up in such a special mode with limited functionality (such as preventing you from checking out a different revision...).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM