We can use the git commit
command to save any changes we make to the local repository. We use the git commit
command with option -m
to create a git commit with a message.
Adding the filenames of moved files in a git commit message is a good practice that helps describe and share our changes with other developers.
To add the filename of a moved file, use the git commit
command with the -m
option as shown below:
git mv filename newName
git commit -m “Moved filename”
filename
: The name of the file being moved.newName
: If it is a file name, the file filename
is renamed to newName
. If it is a folder name, the filename
is moved from the working directory to the folder newName
.As shown in the code snippet above, we use git commit -m "Moved filename"
in combination with the git mv
command to share the name of the moved file with other developers.
Most of the time, we do not work alone on our projects. Instead, there is a team of developers working together. We must add the filename of a moved file to explain to other developers precisely what files we moved in the project and why these changes were necessary.
Consider that we move a file file1.txt
from the working directory to a folder named folder1
using git mv
as shown below:
We can use the git commit
command with option -m
to add the name of the moved file in a commit message.
The code below provides an example of this:
git mv file1.txt file2.txtgit commit -m "Moved file1.txt"
Free Resources