Using FileMerge to resolve conflicts
Default software is sometimes the best way to go
The use different comparison tools can be a tricky decision. However FileMerge is bundled with Xcode and uses easy navigation, syntax-based colouring and the ability to merge in changes.
- Some knowledge of Git
Git: Git is a distributed version-control system for tracking changes in source code during software development
Create a remote on github
In the top right hand corner of github.com (assuming you have an account: if you don’t, create on before continuing with this guide)
Create a suitable repository name (test is a good choice) and then create the repository:
And we initialize this repository with a README:
Create a local git repository
Create a suitable folder, for example test within documents (these commands can be run from anywhere using the terminal)
$ cd ~/documents
$ mkdir test
$ git init
Create a README.md file
$ touch README.md
Make changes to the readme file on your local machine
type the following into README.md, using Xcode or your favourite editor:
Stage and Commit changes
$ git add .
$ git commit -m “readme commit”
Add the remote to the Git repository in the terminal
you can find the link for the repository through the Clone or download green button, available from the main repository screen (most easily accessed by pressing the repository name in the top-left hand corner of the screen)
Then within the terminal you can add the remote:
git remote add origin https://github.com/stevencurtis/test
Make changes to the readme file on web repo
Click on README.MD in your web browser
We can then edit the README.md by pressing the pen symbol at the right-hand side of readme
and we create at the three lines of text as follows:
remembering to press commit at the bottom of the screen.
Pull information using terminal
remembering to add the unrealated histories as below. This is because we have created the remote, and the master branch on our computer entirely seperately.
$ git pull origin master — — allow-unrelated-histories
You have now created a conflict
We can move to using opendiff to solve the merge conflicts
$ git mergetool
If we have typed the two files correctly, we will have two differences.
We want to choose the left hand side for the first change (the local), and the right-hand side for the second change.
I find this easiest by using the cursor keys (up and down to choose the difference, left to will make the arrow face left and we choose the left hand version and the right will do the reverse). The result of the changes will be shown in a third window at the bottom of the screen.
An alternative is under actions you have choices as to whether choose left, right, both (left first), both (right first) or neither.
In either case, you must save the changes when you close the file (so click save).
Back in the terminal you must confirm that the merge was successful (and of course you can check this in your text editor).
If you say no to this question, you will be left with lots of temporary files that you will need to choose w
Cleaning up changes
If your change was successful, most of the temporary files are removed from your folder, with only one remaining (README.md.orig). To remove this we can clear any untracked files
$ git clean -f
or, if we are unsure which files are tracked (and do not want to go to the trouble of a git status to check it), we can remove just that specific file
$ git rm readme.md.orig
$ git commit -m “readme changes”
then to be able to push set the upsteam master, and push the changes
$ git push — set-upstream origin master