Git advanced
Contents
- ⛙ Merge conflicts
- 📦 Stashing
- ✂️ Splitting commits
- 👉 Git blaming
Merge conflicts
And how to quickly solve them
Preventing merge conflict in the first place
- Keep formatting consistent acros the whole project
- Make clear and small commits
- Never do unrelated user stories in your commits
- Always include trailing newlines in files
- Tab vs space, decide and document before you code
The hard part of merging is figuring out what the new code is ment to done, in the following code, without any previous knowledge, it is hard to see what's supposed to happen without actually testing different variations of the code
Example merge conflict
Use a different merge style to clearly show the parent before you merge
Differend merge style
git config --global merge.conflictstyle diff3
Stashing
Putting your changes in a box, so you can review other peoples boxes
A temporary commit, for only yourself
- git stash -u
# Makes a temporary commit for yourself - git stash list
# Shows a list of all your local stashes - git stash pop
# Applies the latest stash - git stash drop {name}
# Deletes a named it stash - git stash clear
- # Removes all git stashes
Use cases
- When you need to checkout some code for review
- When you worked on the wrong branch, and you cannot switch back
- When you want to reset the branch state
- Use `git reset` for this - When you have finished a task, use a normal commit for this
Use when
Don't use when
Splitting commits
The art of splitting changes, so it looks better in the history
- Easier to solve merge conflicts because history looks cleaner
- You can more easily `git revert` broken changes
- Because the changes are small
Why?
Splitting up multiple files
- git add file1
- git commit
- git add file2
- git commit
As you can see, splitting changes in different files is easy, because of this, our sass structure has protected us from most conflicts
Splitting up changes in the same file
Use `git add -p`
y - Yes, add this hunk
n - No, don’t add this hunk
d - No, don’t add this hunk and all other remaining hunks.
s - Split the hunk into smaller hunks.

Git blaming
Confirming when and what broke the project
- Used when you want to see who touched a line in a file for the last time
- Use like `git blame <file>`
git blame

-
Used for an overview of the branch structure
- Use like `gitk` or `gitk --all`
gitk

The end
See also:
- `git help blame`
- `git help merge`
- `git help add`
- `git help commit`
Git advanced
By Fernando van Loenhout
Git advanced
- 53