Sometimes in Git we will do a merge that will need manual intervention.
If you are merging your own stuff in with your own stuff then most of the time you are going to know which bit of code to keep or if to keep them both.
Things get interesting when either of the following two cases apply;
- You are merging in someone else’s code
- You can’t remember why you had written the code that is causing the issue.
Both of these cases can be solved by a using git’s blame.
git blame will show you a line by line breakdown of who wrote what line of code and as part of what commit and why this is useful for helping with merges is that it will;
- Let you know who you need to contact to discuss what needs to happen with this merge if it is non-obvious.
- Give you a commit hash that you can then query to find out the bigger picture and the context of the smaller change that is currently causing you issues.
To run git blame on a file simply call git blame my_file_name.rb and the output will be the contents of the file with each line prepended with the commit hash, the commiter and the the date and time it was commited.