Let's learn how to move a file within the repository.
Now we will create the structure in our repository. Let us move the page in the lib directory.
RUN:
mkdir lib
git mv hello.html lib
git status
RESULT:
$ mkdir lib
$ git mv hello.html lib
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: hello.html -> lib/hello.html
#
By moving files with git, we notify git about two things
hello.html
file was deleted.lib/hello.html
file was created.Both facts are staged immediately and ready for a commit. Git status command reports the file has been moved.
A positive fact about git is that you don’t need to think about version control the moment when you need to commit code. What would happen if we were using the operating system command line instead of the git command to move files?
The following set of commands have the same result as the ones we used above, but the ones below require a little more work.
We can do:
mkdir lib
mv hello.html lib
git add lib/hello.html
git rm hello.html
Let us commit this movement.
RUN:
git commit -m "Moved hello.html to lib"