Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Moving Files2:14 with Jay McGavren
Just as the "git rm" command lets you remove files from a repo, the "git mv" command lets you move (or rename) files within a repo.
- We just created an HTML file for our silver medals page, here in
- Let's stage the file for committing:
git add silver.txt
- And then we'll commit it:
git commit -m "Add silver medals"
- Unfortunately, only now do we realize that we needed that file name to be saved with a
.htmlextension, not a
- But we've already committed the file under the wrong name! How can we fix this?
git mv command
- Git offers the
git mvcommand to let you move files around.
- After you type
git mv, you need to provide the name of the file you want to move,
silver.txt, and the file name you want to move it to,
git mv silver.txt silver.html
- If we run
lsnow, we'll see that the
silver.txtfile has been moved to
silver.htmlin our working directory.
- Now let's try running
- We'll see "renamed: silver.txt -> silver.html" in the "Changes to be committed" section.
- That means the file renaming has been staged.
- Now we just need to commit the change:
git commit -m "Rename silver.txt to silver.html"
$ git mv silver.txt silver.html $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # renamed: silver.txt -> silver.html # $ git commit -m "Rename silver.txt to silver.html" [master 9505066] Rename silver.txt to silver.html 1 file changed, 0 insertions(+), 0 deletions(-) rename silver.txt => silver.html (100%)
We just created an HTML file for our silver medals page, here in silver.txt.
With our work saved, we can close our editor.
Let's click back in the console,
make sure that we're in our repository directory, cd medals.
And let's save the file for committing, git add silver.txt.
And then, we'll commit it, git commit -m "Add silver medals".
Unfortunately, only now do we realize that we needed that file name
to be saved with a .html extension, not a .txt extension.
But we've already committed the file under the wrong name.
How can we fix this?
Git offers the git move command to let you move files around.
It's typed as git mv, but the mv is pronounced as move.
Like git rm, the name and syntax of the git mv command
is based on an important Unix command that does the same thing, but outside of git.
After you type git mv, you need to provide the name of the file you want to move,
silver.txt, and the name of the file you want to move it to, silver.html.
Hit Enter to run the command.
There won't be any output.
As usual, that's a good thing.
It means the command worked.
If we run ls now, we'll see that the silver.txt file
has been moved to silver.html in our working directory.
Now, let's try running git status.
We'll see, renamed,
silver.txt to silver.html in the changes to be committed section.
That means the file renaming has been staged.
Now, we just need to commit the change,
git commit -m "Rename silver.txt to silver.html".
Let's run git status again.
And we'll see there are no uncommitted changes.
If we run ls, we'll see the file is still named silver.html.
And when our git repository is cloned,
that's the file name that will be in the clone as well.
You need to sign up for Treehouse in order to download course files.Sign up