In a Git repository, how to properly rename a dire

2019-01-04 04:47发布

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?

10条回答
狗以群分
2楼-- · 2019-01-04 04:59

On https://github.com in their repository interface :

Go to settings --> Repository name --> input your new name in the area.

查看更多
姐就是有狂的资本
3楼-- · 2019-01-04 05:02

You can rename the directory using the file system. Then you can do git rm <old directory> and git add <new directory> (Help page). Then you can commit and push.

Git will detect that the contents are the same and that it's just a rename operation, and it'll appear as a rename entry in the history. You can check that this is the case before the commit using git status

查看更多
啃猪蹄的小仙女
4楼-- · 2019-01-04 05:08

From Web Application I think you can't, but you can rename all the folders in Git Client, it will move your files in the new renamed folders, than commit and push to remote repository.

I had a very similar issue: I had to rename different folders from uppercase to lowercase (like Abc -> abc), I've renamed all the folders with a dummy name (like 'abc___') and than committed to remote repository, after that I renamed all the folders to the original name with the lowercase (like abc) and it took them!

查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-04 05:09

FYI I kept getting "FAILED \ Access denied" when using either Tortoise or the command line options to do the rename. It only work from the the command line option after I had closed the Explorer window.

查看更多
三岁会撩人
6楼-- · 2019-01-04 05:09

I just renamed the directory and then added, committed and pushed to remote. It works fine

mv git add new_dir git commit -m "<>" git push

查看更多
beautiful°
7楼-- · 2019-01-04 05:10

Basic rename (or move):

git mv <old name> <new name>

Case sensitive rename—eg. from casesensitive to CaseSensitive—you must use a two step:

git mv casesensitive tmp
git mv tmp CaseSensitive

(More about case sensitivity in Git…)

…followed by commit and push would be the simplest way to rename a directory in a git repo.

查看更多
登录 后发表回答