minte9
LearnRemember



Conflict

Git won't let you switch branches if you have uncomitted changes that conflicts with that branch.
 
$ git init

(master)
$ touch example.txt
$ echo "master line" > example.txt
$ git add .
$ git commit -m "master commit"

(dev)
$ git checkout -b dev
$ echo "dev line 2" > example.txt
$ git -m -a "m"
$ less example.txt
dev line 2
    # add a line which is in conflict with master

(master)
$ git checkout master
Trying to merge gets conflict.
 
$ git merge dev
Auto-merging example.txt
CONFLICT (content): Merge conflict in example.txt
Automatic merge failed; fix conflicts and then commit the result.

$ less example.txt
<<<<<<< HEAD
master line
=======
dev line 2
>>>>>>> dev

(master|MERGING)
$ git merge dev -X theirs
error: 'merge' is not possible because you have unmerged files ...

Commit reset

 
$ git reset --hard HEAD~1
HEAD is now at d5f8b30 m
       // Undo merge one step

$ git status
# On branch master
# nothing to commit, working directory clean

Merge force

Merge force, keep theirs.
 
 (master)
$ git merge dev -X theirs
    # Merge and keep DEV modifications

$ less example.txt
dev line
    # master file contains now their line



  Last update: 496 days ago