开发者

Changing name of folder in Rails - Git won't let me add to commit

Changing name of folder in Rails - Git won't let me add to commit

Referencing the screenshot above, I changed the name of the lowest-level folder in the tree. For example, I changed "Chips" to "chips." Oddly, Git refuses to recognize the following command when I try to add it to the commit:

git add public/images/chips/

The only way I can get it to add the file to the commit is 开发者_开发知识库by adding an actual file in the subfolder.

Any ideas how to handle?


In general when changing file or directory names, you'll want to use the following:

git mv oldfile newfile

This will tell git to actually add the changes so that you can commit them. So, try manually changing it back with

mv chips Chips

and then run

git mv Chips chips


This is probably only an issue when working with an OS that has case-insensitive filesystems, like OSX and Windows. You should do the rename on a unix system / case-sensitive filesystem - it will work there with either way (git mv or first rename, then git add - it will detect the move).

Then back on your case-insensitive system you'll probably get conflicts during the pull. It may help to manually rename there and try the pull again - git should merge these changes properly then (because there're actually none if the commit changed nothing else within that directory).

You can also get around this by some advanced git and rename trickery: Rename to chips-tmp first, commit, then rename to chips, amend your previous commit. Only then push to your upstream repositoy.

Look here:

  • git mv and only change case of directory
  • http://kerneltrap.org/mailarchive/git/2007/8/28/256085


Note that, from March 15th, 2013, you can move or rename a file directly from GitHub.
That means, in your case, you could rename folders on GitHub, then clone your repo in a fresh local repo, with the new names for said folders.

Changing name of folder in Rails - Git won't let me add to commit

You can also move files to entirely new locations using just the filename field.
To navigate down into a folder, just type the name of the folder you want to move the file into followed by /.
The folder can be one that’s already part of your repository, or it can even be a brand-new folder that doesn’t exist yet!

Changing name of folder in Rails - Git won't let me add to commit


Rollback your changes and run git mv Chips chips


How did you rename the folders? I always move / rename files in my repository using git mv (git help mv). Try mving the files/folders back to what git knew they looked like, then use git's version of move instead?


Try git add -A. This will detect renames/deletes that weren't done through git mv/git rm.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜