Skip to content

Instantly share code, notes, and snippets.

@d-mart
Last active October 6, 2015 02:57
Show Gist options
  • Select an option

  • Save d-mart/2923896 to your computer and use it in GitHub Desktop.

Select an option

Save d-mart/2923896 to your computer and use it in GitHub Desktop.
Handy git commands I won't remember
# from comments http://stackoverflow.com/questions/160608/how-to-do-a-git-export-like-svn-export
git archive --format=tar --remote=ssh://remote_server/remote_repository master | (cd /path/to/dir/ && tar -xf -)
# reset author
git commit --amend --reset-author -C HEAD
# show changes made from a paricular commit (diff format)
git show --pretty="format:" d2e4b49
git show --pretty="format:" --name-only d2e4b49
# regex search for a filename across all branches http://stackoverflow.com/questions/372506/how-can-i-search-git-branches-for-a-file-or-directory
for branch in `git for-each-ref --format="%(refname)" refs/heads`; do
echo $branch :; git ls-tree -r --name-only $branch | grep '<foo>'
done
# http://stackoverflow.com/questions/750172/how-do-i-change-the-author-of-a-commit-in-git
#In the case where just the top few commits have bad authors,
# you can do this all inside git rebase -i using the exec command and the --amend commit, as follows:
git rebase -i HEAD^^^^^^ # as required
# which presents you with the editable list of commits:
pick abcd Someone else's commit
pick defg my bad commit 1
pick 1234 my bad commit 2
# Then add exec ... --author="..." lines after all lines with bad authors:
pick abcd Someone else's commit
pick defg my bad commit 1
exec git commit --amend --author="New Author Name <[email protected]>" -C HEAD
pick 1234 my bad commit 2
exec git commit --amend --author="New Author Name <[email protected]>" -C HEAD
# command to delete all remote branches for a given remote - Use e.g. on own fork to clean it up
git branch -r --merged master | grep -v master | grep <some_remote> | sed -e 's/\// :/g' | xargs -n2 git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment