git rev-parse --abbrev-ref HEAD
awk -F/ "{print \$NF}" .git/HEAD
Log
git log -1
git show 2a32e8590d5c00364b3c025f4c5a08f7aed26fd8
git log -- oneline -- abbrev - commit -- all -- graph
Show
git show f1ec7a9:lib/perl/Module.pm
Show changes history
git log -GMyChangedString -p
Show file history
commit history
git log -- filename
commit history and diffs
git log -p filename
tig filename, then j, k, d, q
To resolve Ctrl+Y in tig:
stty -a | grep dsusp
stty dsusp undef
stty -a | grep dsusp
git branch -m branch-old branch-new
git push origin :branch-old
git push --set-upstream origin branch-new
Revert a merge to master
git revert -m 1 d33e978a8be12e8023dac8aba2cc126098dfa15d
(where d33e97... is the merge commit)
Revert commit
git revert <hash>
Delete a branch
git branch -D bugfix
git push origin --delete bugfix
Revert branch to remote
git reset --hard origin/bugfix
Resolve a file (ours is HEAD, theirs is trying to merge into HEAD)
git checkout --ours file.c
git checkout --theirs file.c
git add file.c
git commit -m 'File added'
Named stashes
git stash save "guacamole sauce WIP"
git stash apply stash^{/guacamo}
Git patch
git format-patch branch-18 --stdout > 18.patch
git format-patch HEAD^ --stdout > 18.patch
git apply --stat 18.patch
git apply --check 18.patch
git apply 18.patch
Git diff
git diff --stat -p master..branch
git diff branch^..branch
git diff HEAD~1 --stat
Git bisect
git log --since=1.weeks --reverse | head -n3
git bisect start
git bisect badgit bisect good <hash>
git bisect run my_script arguments
git bisect reset
Git force push
To force a push to only one branch, use a + in front of the refspec to push
git push origin +branch
git push --force-with-lease origin branch
If git lock occurs
ps -ef | grep git
rm .lock
git fetch --all --prune
(cleans up old branches locally that are no longer on the git remote server)
git checkout branch
git pull
Bring back the removed file
Existing commit
get a list of removed files
git checkout HEAD
OR
git checkout --
then restore needed file
git checkout HEAD file1 file2
OR
git checkout -- file1 file2
OR
git checkout HEAD^ -- file1 file2 file3
Previous commit
git reset HEAD^ -- file1 file2
git checkout -- file1 file2
Previous commits
git reset HEAD~4 -- file1 file2
git checkout -- file1 file2
How many commits is HEAD far away from origin/master?
git rev-list --count HEAD ^origin/master
Clean git dangling objects
git fsck
git gc --prune=now
Rebasing a big big branch
http://blog.appsignal.com/blog/2016/09/27/git-rebasing-strategies.html
Advanced Git commands
https://hackernoon.com/lesser-known-git-commands-151a1918a60
Git notifications link:
https://github.com/notifications/participating
Git pull requests link:
https://github.com/pulls/mentioned
Hide Whitespace Noise:
git diff -w
git show -w
?w=1
Show Changed Words:
git diff --word-diff
Which Branches You Recently Worked On:
recent = ! git for-each-ref --count=10 --sort=-committerdate refs/heads/ --format="%(refname:short)"
Remind Yourself What You’ve Been Up To:
git log --all --oneline --no-merges --author=<your email address>
Current hash:
current = ! git log -1 --pretty=oneline | cut -d' ' -f1
git rev-parse HEAD
Empty commit:
git commit --allow-empty -m "trigger build"
Lines removed so far:
git log --author='Per List' --after='2000-01-01' --word-diff --unified=0 | sed -ne '/^\[-/p' | sed -e '/{+/d' | wc -l
Git CRLF mess:
https://stackoverflow.com/questions/10418975/how-to-change-line-ending-settings
No comments:
Post a Comment