Rewrite git history replacing a word in every single file

miviclin

I want to rewrite the git history of my repository with git-filter-branch to replace all occurrences of "foo.bar" with "bar.foo" in all files.

How can I achieve this?

Update:
I've being playing with the --tree-filter parameter and I've been able to replace the word in a specified file with this:

git filter-branch -f --tree-filter '
    if [ -f testfile ]
    then
        sed -i s/foo.bar/bar.foo/g testfile
    fi ' -- --all

This seems to be the closest I can get to achieve what I wanted.

torek

The tree filter is run on every tree being filtered, one tree at a time.

In terms of its effect, you can imagine it as if you had done:

git checkout <rev>

so that the work directory now contains the tree associated with the given revision. (In fact, it does pretty much check out every revision, into a temporary directory, which is why it's so slow. See also the -d flag.) If you want a change made to every file in the tree, you might do:

find . -type f -print | xargs sed -i '' -e 's/foo\.bar/bar.foo/g'

The special thing about --tree-filter is that it automatically does any required git add and/or git rm (hence -i ''; -i .bak would git add all the .bak files).

(Remember to use --tag-name-filter if you have tags, and beware of signature removal on annotated tags.)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Rewrite git history replacing a word in every single file

From Dev

Rewrite git history according to a .mailmap file

From Dev

git extensions single file history only diffs

From Dev

Replacing </div> with a word in a file

From Dev

Move single Git file between branches with its' history

From Dev

Git: How to save a branch's history into a single file

From Dev

Can git-svn not rewrite git history?

From Dev

Replacing the Prod Repo after rewriting git history?

From Dev

GIT: How do I add a file to the first commit (and rewrite history in the process)?

From Dev

GIT: How do I add a file to the first commit (and rewrite history in the process)?

From Dev

Git commands that could break/rewrite the history

From Dev

Does 'git squash' (after pushing) rewrite the history?

From Dev

Git history rewrite messed up branch

From Dev

Git history rewrite messed up branch

From Dev

Moving a file in git history

From Dev

Replacing the word(case senstitive) in a file

From Dev

Finding file and replacing word with some specific word

From Dev

replacing all numbers by a single word in text files

From Java

Git copy file preserving history

From Dev

Rename a file on git and keep history

From Dev

Force file history associations with Git

From Dev

Count every fourth word in a file

From Dev

Rewrite every request to one file with url as parameter

From Dev

Pulling the first record of a history file for every unit

From Dev

Check Word Document Style for every single lines

From Dev

Text - one label for every single word

From Dev

GIT Rebase Gone Wrong - Possible to Rewrite History to Fix

From Dev

When is it safe to rewrite git history when local branches are present?

From Dev

git rewrite history from fast-forward to no-fast-forward

Related Related

  1. 1

    Rewrite git history replacing a word in every single file

  2. 2

    Rewrite git history according to a .mailmap file

  3. 3

    git extensions single file history only diffs

  4. 4

    Replacing </div> with a word in a file

  5. 5

    Move single Git file between branches with its' history

  6. 6

    Git: How to save a branch's history into a single file

  7. 7

    Can git-svn not rewrite git history?

  8. 8

    Replacing the Prod Repo after rewriting git history?

  9. 9

    GIT: How do I add a file to the first commit (and rewrite history in the process)?

  10. 10

    GIT: How do I add a file to the first commit (and rewrite history in the process)?

  11. 11

    Git commands that could break/rewrite the history

  12. 12

    Does 'git squash' (after pushing) rewrite the history?

  13. 13

    Git history rewrite messed up branch

  14. 14

    Git history rewrite messed up branch

  15. 15

    Moving a file in git history

  16. 16

    Replacing the word(case senstitive) in a file

  17. 17

    Finding file and replacing word with some specific word

  18. 18

    replacing all numbers by a single word in text files

  19. 19

    Git copy file preserving history

  20. 20

    Rename a file on git and keep history

  21. 21

    Force file history associations with Git

  22. 22

    Count every fourth word in a file

  23. 23

    Rewrite every request to one file with url as parameter

  24. 24

    Pulling the first record of a history file for every unit

  25. 25

    Check Word Document Style for every single lines

  26. 26

    Text - one label for every single word

  27. 27

    GIT Rebase Gone Wrong - Possible to Rewrite History to Fix

  28. 28

    When is it safe to rewrite git history when local branches are present?

  29. 29

    git rewrite history from fast-forward to no-fast-forward

HotTag

Archive