Skip to content

Instantly share code, notes, and snippets.

@dannyroberts
Last active May 16, 2025 10:26
Show Gist options
  • Save dannyroberts/857b9f7e52acd6b83c89 to your computer and use it in GitHub Desktop.
Save dannyroberts/857b9f7e52acd6b83c89 to your computer and use it in GitHub Desktop.

Revisions

  1. dannyroberts revised this gist Mar 17, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion preserving-history.md
    Original file line number Diff line number Diff line change
    @@ -13,4 +13,6 @@ and, when you commit, it'll preserve this history of those files.

    Things that still work:
    - git blame
    - git merge with code that branched off before the renaming (incredible!)
    - git merge with code that branched off before the renaming (incredible!)
    - you may have to set `merge.renamelimit` to something higher for this to work, i.e.
    `git config merge.renamelimit 4000`
  2. dannyroberts created this gist Mar 17, 2015.
    16 changes: 16 additions & 0 deletions preserving-history.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # Did you know...
    ...that git lets you move and rename whole directories while preserving the git history of those files?

    If you run
    ```bash
    git read-tree --prefix=$NEW_PATH -u master:$OLD_PATH
    rm -rf $OLD_PATH
    # ...you probably want to change some imports...
    git commit -m $MESSAGE
    ```
    that will move the directory tree to the new location,
    and, when you commit, it'll preserve this history of those files.

    Things that still work:
    - git blame
    - git merge with code that branched off before the renaming (incredible!)