Today at work I needed to move and rename a ton of files, but I also needed to make sure that the Git history followed. When I tried to move the files manually, SourceTree thought I deleted the files and then created new files elsewhere. When I commit files like this, SourceTree is usually smart enough to catch on, but it wasn’t happening. No good.
It took me a while to figure this all out, so I figured I’d share.
In the root, I had nearly 1000 files with the following naming schema:
L1T1-page01.cfm (standing for lesson 1, topic 1, page 1). All together there are 8 lessons, each lesson has multiple topics, and each topic has multiple pages.
I needed to move these files from the root and into organized folders:
L1T1-page01.cfm would reside at
So I had to
git mv these files myself; a new-to-me command.
First, I moved batches of files belonging to the same topic to their respective topic folders by hitting this command:
(Can I get a hell yeah for that asterisk?)
After I moved the files I realized I wanted to shorten the filenames from
Within each topic folder, I hit the following command:
Update 1/7/2014: I revisited this post, I’m so glad I had save these commands! I found that instead of going into individual folders, I can run the commands from the
lessons/ folder and let it ride:
It worked. Just by looking at the last command, I know there’s a smarter way to write it. Nevertheless, it worked and I’m kind of proud of myself.
As I was figuring this out, I imagined the scene from Hook where Peter begins to remember how to play pretend and the children are like “You’re doing it, Peter.”