Drusantia
3/27/2019 - 12:45 PM

GIT magic (squash commits, rebase master)

Rebasing master to current branch rewrites history in a way that all the changes occurred on master gets pulled and placed before the commits done on current bracnh.
This way it looks like all the changes happened since one started to work on a branch happened after the last commit on master.

git fetch
git rebase origin/master
git push origin +BRANCH_NAME 
	// + makes a force push (only for this branch's refs)
// or: git push --force
If only you work on the branch:

1.
// be on the branch you want to squash
git rebase -i HEAD~4 
	// where 4 is the number of commits to squash

2.
pick xxxxx 
squash xxxxx
squash xxxxx
squash xxxxx
squash xxxxx
	// change all, but the first "pick" command to "squash"

3.
//set custom commit message for the squashed commit

4.
git push origin +BRANCH_NAME 
	// + makes a force push (only for this branch's refs)
If more people works on the branch

1.
git pull --rebase
git add .
git rebase -i HEAD~4
	// where 4 is the number of commits to squash

2.
pick xxxxx 
squash xxxxx
squash xxxxx
squash xxxxx
squash xxxxx
	// change all, but the first "pick" command to "squash"

3.
//set custom commit message

4.
git pull --rebase

5.
//resolve conflicts, keep own code

6.
git add .

7.
git rebase --continue

8.
git push origin +BRANCH_NAME
	// + makes a force push (only for this branch's refs)

Disable the line ending warning (eg. Sourcetree complains if the last line of a file is not an empty one):

git config --global core.safecrlf false

After .gitignore changes, it removes now-should-be-untracked files:

git rm -r --cached . && git add -A && git commit -am 'Updated .gitignore, removing currently tracked, should-be-removed files.'

Undo a commit and redo:

git commit -m "Something terribly misguided"
git reset HEAD~
<< edit files as necessary >>
git add .
git commit -c ORIG_HEAD

https://stackoverflow.com/questions/927358/how-to-undo-the-last-commits-in-git/927386#927386

Counts how many lines of code did which contributor

git ls-files | while read f; do git blame -w --line-porcelain -- "$f" | grep -I '^author '; done | sort -f | uniq -ic | sort -n