Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

alt text

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?

like image 871
keruilin Avatar asked Oct 26 '10 21:10

keruilin


People also ask

Can I rename a git folder?

To rename any file or folder, use git mv command which takes two arguments. The first argument is the source and the second is the destination. We can easily rename any file using the git command and the new name will be assigned to that file. We can rename the file using GitHub or the command line.

How Add folder to git commit?

To add and commit files to a Git repository Create your new files or edit existing files in your local project directory. Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.

Can git track folders?

Git will only track Files and the changes in them. So folders are tracked as part of the file changes in them. In order to create an empty folder and commit it, there have to be some files inside it.

What does a folder with an arrow mean in GitHub?

On your machine, if you navigated to the directory with the arrow and tried to view hidden files, you'd see a . git folder, indicating that it is a repository. This means that it is a repo contained inside the outer repo that you had pushed to GitHub.


2 Answers

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
like image 91
Topher Fangio Avatar answered Sep 21 '22 14:09

Topher Fangio


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
like image 35
hurikhan77 Avatar answered Sep 25 '22 14:09

hurikhan77