Handling GIT Conflicts
I am attempting to push when I experience a conflict (ruby-1.9.2-p180)
cts_work/diaspora_cts git:(master)> git push origin master
To git@gitorious.org:diaspora_cts/diaspora_cts.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to ‘git@gitorious.org:diaspora_cts/diaspora_cts.git’
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. ‘git pull’) before pushing again. See the
‘Note about fast-forwards’ section of ‘git push –help’ for details.
First, see if the conflict can be automatically resolved:
cts_work/diaspora_cts git:(master)> git pull
error: Your local changes to the following files would be overwritten by merge:
db/schema.rb
Please, commit your changes or stash them before you can merge.
Aborting
Git status shows that your state is conflicted:
cts_work/diaspora_cts git:(master)> git status
# On branch master
# Your branch and ‘origin/master’ have diverged,
# and have 2 and 1 different commit(s) each, respectively.
#
nothing to commit (working directory clean)
IMPORTANT – If you can resolve the conflict do so (normal procedure), this procedure presumes you wish to write the conflicting updates to a branch.
Reset your tree to just your unmerged updates:
cts_work/diaspora_cts git:(master)> git reset –hard HEAD
HEAD is now at 340a54e changes amde
Create a branch, use a name which suggests a conflict:
cts_work/diaspora_cts git:(master)> git branch conflict_stuff
cts_work/diaspora_cts git:(master)> git branch
conflict_stuff
* master
Reset your tree to the prior revision:
cts_work/diaspora_cts git:(master)> git reset –hard HEAD
HEAD is now at 340a54e changes amde
Pull the other persons changes:(Do not do git pull but always git fetch + git merge)
cts_work/diaspora_cts git:(master)> git fetch
cts_work/diaspora_cts git:(master)> git merge origin/master
Merge made by recursive.
app/controllers/sessions_controller.rb | 21 ++++++—-
app/models/profile.rb | 3 +-
app/views/layouts/application.html.haml | 14 +++—
app/views/people/_profile_sidebar.html.haml | 15 +++++–
config/locales/diaspora/en.yml | 1 +
db/migrate/20110226134747_add_columnto_profile.rb | 2 +
db/schema.rb | 5 ++-
lib/tasks/profile_update.rake | 42 +++++++++++++++++++++
public/javascripts/application.js | 2 +-
9 files changed, 81 insertions(+), 24 deletions(-)
create mode 100644 lib/tasks/profile_update.rake
Switch back to your branch:
cts_work/diaspora_cts git:(master)> git checkout conflict_stuff
Switched to branch ‘conflict_stuff’
cts_work/diaspora_cts git:(conflict_stuff)> git status
# On branch conflict_stuff
nothing to commit (working directory clean)
Push your conflict branch back to the repoistory:
cts_work/diaspora_cts git:(conflict_stuff)> git push origin master
Counting objects: 11, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 861 bytes, done.
Total 8 (delta 5), reused 0 (delta 0)
=> Syncing Gitorious… [OK]
To git@gitorious.org:diaspora_cts/diaspora_cts.git
d25e82a..c977122 master -> master