I am trying to rename a file in a local .git directory
:
git mv MyProj/src/ts0621/foobar.c NewProjName/src/ts0629/foobar.c
Yet, git fails with:
fatal: renaming 'MyProj/src/ts0621/foobar.c' failed: No such file or directory
I could swear that I had git mv
working for me when renaming a subdirectory, but for some reason a simple rename of a file doesn't work. Why?
(I, of course, verified that the file MyProj/src/ts0621/foobar.c
exists before attempting to issue this command)
git-mv - Move or rename a file, a directory, or a symlink.
We use the git mv command in git to rename and move files. We only use the command for convenience. It does not rename or move the actual file, but rather deletes the existing file and creates a new file with a new name or in another folder.
Git move or mv helps us to rename or move files within a git repository without deleting its history. If we move or rename a file within a git repository then it thinks that a file is deleted and a new file is added.
No. The short answer is NO. It is not possible to rename a file in Git and remember the history.
Probably, because NewProjName/src/ts0629 doesn't exist
Try
mkdir -pv NewProjName/src/ts0629
git add NewProjName/src/ts0629
add -f , if the path is relative, to increase git mv -f "originPath" "newPath"
git mv -f MyProj/src/ts0621/foobar.c NewProjName/src/ts0629/foobar.c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With