Git tricks
(likely to add how-to’s as we go ahead)
Splitting a diff with Sourcetree
- check out a new branch
- cherry pick your original diff onto the new branch
- or check out the new branch directly on top of your original branch
- using sourcetree, revert changes that you don’t want
- note: this is Windows and Mac only. 😞
- repeat from #1 until you’ve created all your component diffs
- optionally stack them using rebase Splitting a diff by hand
- make a copy of your branch in case something goes horribly wrong, or be comfortable with reflog
- squash everything using
git rebase -i
git reset HEAD~1
to unstage your one and only commit- split into one commit per diff
git add <filename>
for all the files you want in this commit- if you only want some of the changes within a file, use
git add -p <filename>
, then hit yes/no/split/edit for each chunk - you usually won’t need edit
- if you only want some of the changes within a file, use
git commit -m <message>
(not-a
!!!)- Repeat for each commit. You can use
git commit -a
for the last one.
git branch
until you have one branch per split- for each branch,
git rebase -i
and remove the last N commits that you don’t want - for each branch,
arc diff <hash>
wherehash
is the previous git commit hash, so that your diff only has one commit in it. Make sure you specify dependent revisions in phabricator.
NOTE: An alternative to removing commits with rebase
is to add commits with git cherry-pick
Squash
git rebase -i
- Except for the first line, replace all instances of
pick
withfixup
Merge
in ~/.gitconfig
:
[merge]
conflictstyle = diff3
http://www.ryanzec.com/2014/12/13/git-merge-conflict-style-diff3/
Undo
git reflog
git reset --hard <hash>
git checkout -b mynewbranch
Rebase
git rebase -i <destination>