Now let's look at another improvement that we can bring to git
. Most tasks are easy to execute from the command line, but some tasks, such as merging, require a specialist's eye for understanding the different format.
Let's open the feature
file from our previous chapter, edit it, add a new line, and save it:
git diff
The git diff
command will show us colored text explaining the differences between the git
file and the modified file, but some people find this format hard to understand:
Luckily, we can tell git
to use external tools when it comes to merge and one external tool that we can use is called Meld. Let's install it using the following:
sudo apt install meld
After this, we can run the following command:
git difftool
It will ask us if we want to launch Meld as an external program for viewing the file. It's also giving us a list of tools that it can use for displaying the difference. Hit y
to open Meld:
Now we can easily see the two files side by side and the differences between them. We can see that 1
has been changed to 2
and a new line has been added. Based on this output we can easily decide if we want to add it or not. Let's commit the file as it is.
Next, we will look at merge conflicts. Let's manually create a branch called test and edit the same file, commit it, and then switch back to the develop branch. Let's update the same file, commit it, and then try to merge the test
branch: and, of course, there is a merge conflict.
For resolving the conflict, we will be using the following command:
git mergetool
Again, it offers to open Meld. In Meld we can see the three files:
Let's say that we decide the correct version for the feature is 4
and that we also want to add of text
:
git commit -a
You can see the predefined commit message. Don't forget to remove the temporary file that was created at the merge:
In general, most modern IDEs offer plugins for working with git
, including merging and diffs
. We recommend that you get more acquainted with the command-line tools, because then you don't need to learn a new git
plugin when switching from one IDE to another.
The git
command works the same way across Linux, Mac, and Windows. It is a tool that developers use a lot and being fluent in it will boost your productivity.
18.191.147.190