git tips and tricks
How do I change the author of my commits?
Whilst I was going through the log of my Git commits, I had noticed some inconsistencies with the author value of some commits. They were all from me, but with different values, so I decided to try and fix that by setting the author and the email values to universal values. To do so, I used the following command:
git filter-branch --commit-filter \ 'export GIT_AUTHOR_NAME="Author Name"; \ export GIT_AUTHOR_EMAIL=authoremail; \ export GIT_COMMITTER_NAME="Committer Name"; \ export GIT_COMMITTER_EMAIL=committeremail; \ git commit-tree "[email protected]"'
Which I found whilst reading could I change my name and surname in all previous commits? question on StackOverflow.
Next, push changes:
git push -u -f origin --all
- -u I used it because I had almost all commits out of sync after that change, and this is useful to refresh the association between local branches and remote
- -f Force push
- –all Push all branches
Merge onto local
git fetch origin master git reset --hard origin/master
How many lines of code do I have?
Reading the most upvoted answer for the How many lines of code is Facebook? question, I found this git gem.
git ls-files | xargs cat | wc -l
Obviously the command can be extended and adjusted to custom needs