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?
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.
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.
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.
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.
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:
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