I have a headless raspberry pi box with a local git repo of some code I wrote. I had made modifications to this code and then wanted to sync it with the remote repo. So I did a stash, and then a pull. Git complained that there was a merge conflict. Okay fair enough I can resolve it by hand. Normally on a workstation I'd use meld or something like that, but this little pi box is command line only.
What's the procedure here? Is there a command line approach to this? I could do it by hand too but I'm not sure on the steps. Most of what I've found searching is all about using gui merge tools.
Thank you.
CodePudding user response:
So when you get a merge conflict:
> git merge twig
Auto-merging ChangeLog
CONFLICT (content): Merge conflict in ChangeLog
Automatic merge failed; fix conflicts and then commit the result.
You can check which files have conflicts with git status
in part "
Unmerged paths":
> git status
On branch master
Your branch is up to date with 'origin/master'.
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Changes to be committed:
modified: README
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: ChangeLog
So in my case the problem is the ChangeLog file, let's see where's the conflict with git diff
:
> git diff
diff --cc ChangeLog
index 154c5a628,3829e837b..000000000
--- a/ChangeLog
b/ChangeLog
@@@ -1,4 -1,4 1,8 @@@
<<<<<<< HEAD
2023-01-27 ME <[email protected]>
=======
2023-01-27 Other person <[email protected]>
>>>>>>> twig
As you can see the conflicts in files are literally marked by git by adding <<<<<<< HEAD
, =======
, and >>>>>>> mergeSource
sequences.
<<<<<<< HEAD
// Some edit
=======
// Conflicting edit
>>>>>>> twig
You can fix it be editing the file and deciding which version to choose, or maybe a mix of versions:
# it's certainly me
pico ChangeLog
2023-01-27 ME <[email protected]>
And then I can mark the ChangeLog conflict as resolved by staging it:
git add ChangeLog
Go over all the files which have conflicting changes, fix all the conflicting issues, add them to staging. When you are done, you can resolve the conflict by commiting fixes:
git commit
Merge branch 'twig'
# Conflicts:
# ChangeLog
#
# It looks like you may be committing a merge.
# If this is not correct, please remove the file
# .git/MERGE_HEAD
# and try again.
All that said if you are getting such conflicts then there's something incorrect in your sync/git procedures. Maybe you are using git commit --amend
to change commits that were already sent to the remote repo (raspberry pi)?