In a Git repository, how to properly rename a directory? I think it should work to copy the directory to be renamed to a new directory with desired name, and delete the old directory, and git add
, git commit
and push
everything. But is this the best way?
相关问题
- How to access the camera from my Windows Phone 8 a
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- git: retry if http request failed
1. Change a folder's name from oldfolder to newfolder
2. If newfolder is already in your repository & you'd like to override it and use:- force
Don't forget to add the changes to index & commit them after renaming with git mv.
3. Renaming foldername to folderName on case insensitive file systems
Simple renaming with a normal mv command(not git mv) won’t get recognized as a filechange from git. If you try it with the ‘git mv’ command like in the following line
If you’re using a case insensitive filesystem, e.g. you’re on a Mac and you didn’t configure it to be case sensitive, you’ll experience an error message like this one:
fatal: renaming ‘foldername’ failed: Invalid argument
And here is what you can do in order to make it work:-
This splits up the renaming process by renaming the folder at first to a completely different foldername. After renaming it to the different foldername the folder can finally be renamed to the new folderName. After those ‘git mv’s, again, do not forget to add and commit the changes. Though this is probably not a beautiful technique, it works perfectly fine. The filesystem will still not recognize a change of the letter cases, but git does due to renaming it to a new foldername, and that’s all we wanted :)
If you receive this error: fatal: renaming ‘foldername’ failed: Invalid argument
Try this:
git mv foldername tempname && git mv tempname folderName
Then re-add and commit.
Simply rename the folder. git is a "content-tracker", so the SHA1 hashes are the same and git knows, that you rename it. The only thing that changes is the tree-object.