Git Lesson 2: dealing with conflicts
CS 5010
“Bootcamp”
Learning Objectives
A Commit
my-project
docs
manual.docx
user_docs.docx
src
main.rkt
module1.rkt
module2.rkt
module3.rkt
.git
commit
When you do a “commit”, you record all your local changes into the mini-fs.
The mini-fs is “append-only”. Nothing is ever over-written there, so everything you ever commit can be recovered.
Remember the basic story from the preceding lesson
Synchronizing with the server (1)
my-project
docs
manual.docx
user_docs.docx
src
main.rkt
module1.rkt
module2.rkt
module3.rkt
.git
push
At the end of each work session, you need to save your changes on the server. This is called a “push”.
Now all your data is backed up.
your local machine
a server, somewhere on the internet, eg. github.com
Synchronizing with the server (2)
my-project
docs
manual.docx
user_docs.docx
src
main.rkt
module1.rkt
module2.rkt
module3.rkt
.git
pull
To retrieve your data from the server, you do a “pull”. A “pull” takes the data from the server and puts it both in your local mini-fs and in your ordinary files.
If your local file has changed, git will merge the changes if possible. If it can’t figure out how to the merge, you will get an error message. Dealing with this is beyond the scope of this tutorial ☹
your local machine
a server, somewhere on the internet, eg. github.com
pull
Now it’s time to deal with conflicts
Q: When might this happen?
A: When your partner committed some changes to the server, which you don't have.
Your partner's work (on the server)
Your work (on your local machine)
Your last pull
Result of Syncing
Your partner's work (on the server)
Your work (on your local machine)
Your changes are applied to the latest version on the server. This is called "rebasing"
Combined work now lives on both the server and your local machine.
Most of the time, this works well
What will you see?
So, click on tools and open a shell
Don't panic!
First, look at the file in an editor
This is what we’re going to do
Here's what the conflicted file looks like (in emacs)
what's on the server
what's on the local machine
Next: edit the file the way you want it
no more >>>'s
add the fixed-up file to the commit
tell git to continue to the next change
ok! we are ready to sync
if there were more conflicts, we'd have to do this process for each of them.
And we're ready to get back to work
Observe that both commits are now in your history
Summary
Next Steps