Git
Various Git aliases from others
Section titled “Various Git aliases from others”Push existing repository to new remote
Section titled “Push existing repository to new remote”git remote add <name of new remote> <HTTPS or SSH URL>git push <name of new remote> masterPretty-print branch graph
Section titled “Pretty-print branch graph”git log --all --decorate --oneline --graphMove ‘master’ back
Section titled “Move ‘master’ back”git checkout mastergit reset --hard <old_commit_id>git push -f origin masterReplay changes from ‘master’
Section titled “Replay changes from ‘master’”git checkout mastergit pullgit checkout different_branchgit rebase -Xtheirs mastergit push --forceShow changed files in commit hash
Section titled “Show changed files in commit hash”From here.
git diff-tree --no-commit-id --name-only <commit hash>Create patch file from diff
Section titled “Create patch file from diff”git diff file.json > file.patchCreate patch file from commit
Section titled “Create patch file from commit”git show <commit hash> > commit.patchApply patch file
Section titled “Apply patch file”git apply commit.patchBulk create patch files from files
Section titled “Bulk create patch files from files”From here.
OLDIFS=$IFS; IFS=';' \ blocks=$(git diff | sed -n '/diff/,/(diff|$)/ {/diff / s/^/\;/; p}'); \ for block in ${blocks#;}; do \ echo "$block" > $(echo "$block" | head -n 1 | rev | cut -d "/" -f 1 | rev).patch; \ done; \IFS=$OLDIFSShow diff of stashed hunk
Section titled “Show diff of stashed hunk”git stash show -p [stash@{N}]Bulk create separate stashes of files
Section titled “Bulk create separate stashes of files”git status -s | cut -d " " -f 3 | xargs -I {} git stash push {} -m "{}"Pop every entry from the stash
Section titled “Pop every entry from the stash”git stash list | cut -d ":" -f 1 | xargs -I {} git stash popMove unpushed commits to new branch
Section titled “Move unpushed commits to new branch”git checkout -b new_branchgit checkout mastergit reset --hard origin/masterCopy commit to current branch
Section titled “Copy commit to current branch”git cherry-pick <commit hash>Undo pushed commit that wasn’t pulled
Section titled “Undo pushed commit that wasn’t pulled”git reset HEAD^ --hardgit push --force originView history of specific function in file
Section titled “View history of specific function in file”git log -L :<function>:<file>Speed up Git for larger repositories
Section titled “Speed up Git for larger repositories”git config feature.manyFiles 1Search through history for a word
Section titled “Search through history for a word”git rev-list --all | ( while read revision; do git grep -F 'word' "$revision"; done; )Delete remote branch
Section titled “Delete remote branch”git push origin --delete branch/nameBulk reset author of multiple commits
Section titled “Bulk reset author of multiple commits”git rebase --onto HEAD~9 --exec "git commit --amend --reset-author --no-edit" HEAD~9Re-order commits
Section titled “Re-order commits”git rebase --interactiveSearch for string in a commit message
Section titled “Search for string in a commit message”git log --all -i --grep='something'Search for string in commit contents
Section titled “Search for string in commit contents”git grep 'something' $(git rev-list --all)Clean new untracked files and directories
Section titled “Clean new untracked files and directories”-d: recurse into directories as well-f: go ahead with deletion-n: dry-run
$ git clean -dnWould remove mdbookWould remove public/snippets/$ git clean -dfRemoving mdbookRemoving public/snippets/Find out number of changes for author
Section titled “Find out number of changes for author”git log --pretty=format:'%an' <file> | sort | uniq -c | sort -u | sort -n