Example of Merging Code in Git
In this example, I’ll show you how to do a merge, after a conflict, between
code of two branches. This is the case where Git couldn’t auto-merge.
git checkout master (switches you to the master branch)
vi
testfile (add the following line ``in
testfile and save)
adfasfasdfadf
asdf
a
sdf
asdf
asdfasdf;lkja;kladjsf;klj
git add testfile (allows it to be tracked by Git)
git commit -m ``"adding content for master branch"
-a
git branch ``test
(create the ``test
branch)
git checkout ``test
(switches you to the ``test
branch)
vi
testfile (delete all of the existing content and ``make
your testfile
``in
the ``test
branch ``look
like this:)
;lkajsdf;lkajdsl;kajsdf
;lkajsdf;ladjsl;kadjsf
asdf
asd
fasd
fadsf
git commit -m ``"adding content for test branch"
-a
git merge master (merge contents of this ``test
branch with the master
branch. see below)
your_username$ git merge master
Auto-merged testfile
CONFLICT (content): Merge conflict ``in
testfile
Automatic merge failed; fix conflicts and ``then
commit the result.
vi
testfile (edit this ``file``, resolve the conflicts by getting rid of
the <<<<<<< HEAD:testfileD:testfile, ======= and >>>>>>> master:testfile and
``make
the ``file
look
like how it should)
Assume the ``file``'s contents should ``look
like this:
;lkajsdf;lkajdsl;kajsdf
;lkajsdf;ladjsl;kadjsf
asdf
asd
fasd
fadsf
asdfasdf;lkja;kladjsf;klj
git commit -m ``"adding content for master branch"
-a (to commit your
changes)
From I-ON-RAILS