Systematic Architecture [EN]
The blog on systems development/architecture, to be a beautiful, artistic one.
Saturday, 26 December 2015
How to amend your Git history
How to amend/rewrite Git history/commits ================================ # For specific changes ## Change `oldtext` to `newtext` in all changes in commits: ```bash git filter-branch --tree-filter "find . -exec sed -i -e \ 's/oldtext/newtext/g' {} \;" ``` ## You may need `-f` for the second rewriting ```bash git filter-branch -f --tree-filter "find . -exec sed -i -e \ 's/oldtext2/newtext2/g' {} \;" ``` # For a specific file ## The following example is to remove all the files matching `*-e` in commits. ```bash git filter-branch --force --index-filter \ 'git rm --cached --ignore-unmatch *-e' \ --prune-empty --tag-name-filter cat -- --all ``` # For author info https://help.github.com/articles/changing-author-info/ ```bash #!/bin/sh git filter-branch --env-filter ' OLD_EMAIL="your-old-email@example.com" CORRECT_NAME="Your Correct Name" CORRECT_EMAIL="your-correct-email@example.com" if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] then export GIT_COMMITTER_NAME="$CORRECT_NAME" export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" fi if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] then export GIT_AUTHOR_NAME="$CORRECT_NAME" export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" fi ' --tag-name-filter cat -- --branches --tags ``` References ========== https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment