Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@IanVaughan
Created May 6, 2020 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IanVaughan/2d3446d000cff42f4d1e8e932468cc1c to your computer and use it in GitHub Desktop.
Save IanVaughan/2d3446d000cff42f4d1e8e932468cc1c to your computer and use it in GitHub Desktop.
# Put somewhere in your $PATH, and chmod +x git-rename
# On a branch with files already moved and changed locally but not in git.
# Usage:
# git rename existing-checked-in-filename new-and-changed-filename
#!/usr/bin/env bash
FROM=$1
TO=$2
mv $TO ${TO}-1
git co $FROM
git mv $FROM $TO
git add $TO
git ci -m "Moved $FROM to $TO"
mv ${TO}-1 $TO
git add $TO
git ci -m "Updates to $TO"
@IanVaughan
Copy link
Author

Changes a sandbox from this :

$ git status
On branch change-namespace
Changes not staged for commit:
       deleted:    app/lib/old-namespace/filename.rb

Untracked files:
       app/lib/new-namespace/filename.rb

to this:

$ git log
* 0c9927db - (HEAD -> change-namespace) Updates to app/lib/new-namespace/filename.rb
* dde55f23 - Moved app/lib/old-namespace/filename.rb to app/lib/new-namespace/filename.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment