Trouble merging upstream changes back into my branch

前端 未结 5 487
情书的邮戳
情书的邮戳 2020-12-12 22:17

I\'m running into conflicts while trying to merge upstream changes back into my branch and I\'m not sure how to resolve them.

I created my own fork. I cloned it. I m

相关标签:
5条回答
  • 2020-12-12 22:38

    Run git commit (after adding the files) the second time, not git merge.

    Also the conflict resolution will create files to help you merge. See also git mergetool.

    0 讨论(0)
  • 2020-12-12 22:40

    The "git merge" command tries to incorporate changes from another branch onto the present branch. If the merge is clean, meaning no conflicts, it will commit. Since your merge did have conflicts, it didn't commit. You need to resolve the conflict.

    Pulling the copy from the upstream repo is one way to do that - by accepting the upstream repo's version. You can do that within git using "git checkout --theirs conflicting_file.txt"

    Editing the file to get it into the shape you want is another way.

    Once it's fixed, you need to add using "git add conflicting_file.txt" then commit. Then your working copy is clean and ready for more hacking. Good luck.

    0 讨论(0)
  • 2020-12-12 22:44

    What you are seeing means that automatic merge could not resolve the conflicts in the files. You need to resolve these conflicts manually. Run git mergetool or git gui.

    0 讨论(0)
  • 2020-12-12 22:45

    In Git there are cases merge refuses to even start in order to protect your local changes. This may happen in two cases:

    • You have uncommitted changes in you repository that conflict with merge. The git will refuse to do a merge with the following message:

      error: Your local changes to the following files would be overwritten by merge:
              foo
      Please, commit your changes or stash them before you can merge.
      Aborting
      

      Then you have to either commit the changes first (git commit -a or git add + git commit), or stash them away with git stash save.

    • You are in the middle of some unfinished merge-y operation. There was some conflict, for example

      Auto-merging foo
      CONFLICT (content): Merge conflict in foo
      Automatic merge failed; fix conflicts and then commit the result.
      

      and you have not finished resolving conflicts (by editing files and marking them as resolved with git add, or using some graphical merge tool via git mergetool) and didn't create a final merge commit with git commit -a, or aborted the merge with git reset --hard (NOTE: this will discard all you changes, and you will loose work done on resolving conflicts!!!).

      Or you have just run second git merge too fast, or used git merge instead of git commit to create a merge commit.

      error: 'merge' is not possible because you have unmerged files.
      hint: Fix them up in the work tree,
      hint: and then use 'git add/rm ' as
      hint: appropriate to mark resolution and make a commit,
      hint: or use 'git commit -a'.
      fatal: Exiting because of an unresolved conflict.
      

      Resolve conflicts as described e.g. in old Fun with completing a merge article by Junio C Hamano and finalize a merge with git commit, or discard a merge, or stash it away. Then if you meant to create this second merge, you can do it.

    Sidenote: by default git-aware shell prompt shows if you are in the middle of merge, rebase or applying patches (git am operation). You can also configure it to show if the working directory is dirty (different from latest version, i.e. HEAD).

    0 讨论(0)
  • 2020-12-12 22:52

    After you've resolved a merge, you need to use git add to add the files you've changed to the index, and then commit (like the message says). This says to git "Yes, I really do want to make these changes".

    Remember, always use git add before committing (either normally or committing a merge), if you're using the command line interface. Frontends like magit can streamline this for you so you don't have to worry about typing "git add" every time.

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