GIT traction conflict: if not on any branch?

I have a branch and I edit and write the file. Meanwhile, someone else clicked, changed to the same file.

When I do git pull, I see

First, rewinding head to replay your work on top of it... Applying: add new line Applying: create 1 conf Using index info to reconstruct a base tree... Falling back to patching base and 3-way merge... Auto-merging <filename> CONFLICT (add/add): Merge conflict in <filename> Recorded preimage for '<filename>' Failed to merge in the changes. Patch failed at 0002 create 1 conf When you have resolved this problem run "git rebase --continue". If you would prefer to skip this patch, instead run "git rebase --skip". To restore the original branch and stop rebasing run "git rebase --abort". 

I tried to manually resolve the conflict in the file, however I see that I am not on any branch. I wonder why this is happening.

 git status # Not currently on any branch. # Untracked files: 
+6
source share
2 answers

This is normal. You just need to fix the file and then follow the rebase instructions - usually with --continue .

You solve the problem with

  • edit files to resolve conflict
  • do git checkout --ours -- <filenames> if you know your version will be good.
  • do git checkout --theirs -- <filenames> if they are good.

Follow all of these with git add <filenames> . Please note that --ours and --theirs may be replaced in some cases from what you expect; so check the file that is really uploaded if you use options 2 or 3.

Finish with git rebase --continue (which will commit for you). If you decide to abort, be sure to use git rebase --abort so that git can pull you out of the "not in any industry" condition.

+6
source

I'm not in any branch. I wonder why this is happening?

An attempt to answer this question and help to understand what is happening, and not just a recipe to "get your head back" from a headless state:

  • you seem to be using a git configuration setting ( pull.rebase or branch.*rebase ) that directs git pull to fetch + reinstall, rather than fetch + merge
  • rebase basically plays your local commits over the top of the remote branches (i.e. regardless of the last commit) .. this includes the following:

    • git retrieves a list of local commits since the last pull / pull, and the rest of the guys do on the remote branch
    • in your case, it detects that the above 2 are diverging (so this is not the case with fast-forwarding)
    • it checks the latest revision of the remote branch. Note: it does not check the most remote branch, that is: it does not set the HEAD link to remote / yourbranch because it is forbidden (because it is a mirror only for the remote remote repo, therefore you cannot update it directly using commit), What it means to be in a headless state.
    • it tries to freeze (replay) your commits one on one at this point, creating a similar story for what you did (with the same sequence of differences / patches), except that it is now based on the latest and greatest

      4.1. In the event that any patch leads to conflict during step 4, the process is paused to resolve it. This is when you realize that you are in a strange state: the status says "not on any branch", gitk will not show the header header of the last commit. So just follow the tips git offers: resolve conflicts, generate changes (add git), and then just ..

      4.2. git rebase --continue to resume the process (no commit needed, git will do it for you). Goto 4. Alternatively, you may need to --skip changes to --skip or if you are too confused, --abort will reset everything to where it was before the rebase part.

    • after all the commits are completed (that is: fixed), it moves (resets) your original link to this link to the end of the story with reinstallation (by the way, abandoning the original sequence of commits in favor of the reissued story) .. So, now you are automatically get a new HEAD (your branch ref). The voiceless ends, you would not notice that you were in this state for a moment

If you used git config pull.rebase=false or (branch. * Rebase), you would have avoided this terrible state (and possibly more conflicts) - however, you can get a noisier story with a lot of merges. (Personally, you can also disable this for a single click by going through --no-rebase .

Learn more about rebase: http://git-scm.com/book/en/Git-Branching-Rebasing .

hope this helps.

+6
source

Source: https://habr.com/ru/post/944293/


All Articles