Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

git

How to add filename of moved file in git commit message

Syed Muhammad Ali Mustafa

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.

Syntax

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.

Why do we need it?

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.

Example

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.

Code

The code below provides an example of this:

git mv file1.txt file2.txt

git commit -m "Moved file1.txt"

RELATED TAGS

git

CONTRIBUTOR

Syed Muhammad Ali Mustafa
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring