Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git didn't recognize rename of a file

Tags:

git

I renamed one Java source file from Multiplechoice.java to MultipleChoice.java.

Unfortunately Git didn't recognize this change. So when someone clones or pulls my repository he or she will have to do the renaming manually, because otherwise the project can't build because this class is used in other classes.

How do I make Git recognize this change in order to commit and push it to the repository?

like image 711
Simon Tenbeitel Avatar asked Jul 25 '15 09:07

Simon Tenbeitel


People also ask

How do I get git to recognize a rename?

Git will automatically detect the move/rename if your modification is not too severe. Just git add the new file, and git rm the old file. git status will then show whether it has detected the rename.

Can you rename a file in Git?

In your repository, browse to the file you want to rename. In the upper right corner of the file view, click to open the file editor. In the filename field, change the name of the file to the new filename you want.

What happens if you rename a file that is tracked by Git?

Git keeps track of changes to files in the working directory of a repository by their name. When you move or rename a file, Git doesn't see that a file was moved; it sees that there's a file with a new filename, and the file with the old filename was deleted (even if the contents remain the same).

How do I change a file name in Git bash?

Way 2: Renaming using the Command Line Step 1: Open Git Bash. Step 2: Open the repository. Step 4: Use the “git status” command to check the changes. Step 5: Commit the renamed file.


1 Answers

Use the Git move function:

git mv "Multiplechoice.java" "MultipleChoice.java"
like image 79
SwiftArchitect Avatar answered Oct 23 '22 02:10

SwiftArchitect