February 24, 2010

Git Merge & Git Diff

Boss says: I like both sentences! I want the app to say “My boss is the best boss ever!” on the first line and “Welcome to the best Ruby app ever written!” on the second line

  • Person 1 goes back to master branch: git checkout master
  • Person 1 merges in the best_boss branch git merge best_boss
  • in this case, your merge “fast forwards” because the master branch hasn’t had any changes since the bestboss branch was created. It is simply moved forward to the latest bestboss commit because there are not any conflicts.
  • Person 1 pulls the git repo: git pull (gets master, which in this case is unchanged)
  • Person 1 checks out best_app git checkout best_app
  • git pull origin best_app (gets the best_app branch)
  • Person 1 checks out master git checkout master
  • merge best app into master: git merge best_app

GIT DIFF:

  • git will tell you that the merge failed. To see the difference between the two files, use: git diff
  • another cool way to see the difference is gitk
  • To see the difference in you application & fix the merge conflict, look at hello.rb. Both of the boastful sentences should be in the file with a bunch of extra git syntax around them. Since we want both sentences, we can delete all of the git syntax, leaving just the two sentences. In other merge conflict situations, you may want to delete one version of the code along with the git syntax.
  • git commit -am "fixed merge conflict"
  • git push