3

I have changed the case of some directories in my git repository. Then I pushed them and noticed the cases where not updated.

Then I found this question: git mv and only change case of directory

I have followed the advice to use:

git add -A
git commit --amend -m 'updated cases'
git push origin

but instead of success the git server is returning:

To git@github.com:kyogron/example.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:kyogron/example.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

What can I now do to update the cases without breaking more in my git repo?

Regards,

bodo

PS: To avoid this issue in future you can use:

git config core.ignorecase false
Community
  • 1
  • 1
bodokaiser
  • 15,122
  • 22
  • 97
  • 140

1 Answers1

6

You need:

git push --force

since you have rewritten the last SHA1 with your --amend, after using git mv.

It won't break your repo unless you have other collaborators having already pulled from your previous commit as explained in "How do I push amended commit to the remote git repo?".
(in that case, you would need other options for publishing your fixed commit)


On OsX, this answer does suggest (to avoid this issue):

git config --unset-all core.ignorecase
git config --system core.ignorecase false 

The OP kyogron reports having found a working solution:

  • Create a new branch and checkout this new branch.
  • Then delete the .DS_Store file in the directory of the corrupted directory and rename it to new name.
  • Then remove wrong directory in the repository (you can view them with git ls-files) and commit this change.
  • Again remove the .DS_Store and now rename the directory to the lower case name you want with git mv
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hi, thank you this helped. Unfortunately there are now two different directories in my repo on github. One with upper case and one with lower case which hold the same files. How can remove this one or better go safe and replace every current file with the local state? – bodokaiser Dec 09 '12 at 15:21
  • @kyogron there won't be two directories if you fix your local repo with `git mv` (http://stackoverflow.com/a/3889000/6309) in order to rename directory `A` into directory `a`, and force push it. Make it look good locally, and then force push: you will see the same commit on GitHub. – VonC Dec 09 '12 at 15:26
  • so I followed your advice and tried to use git mv. Git mv returned that there is no Applications. Even github shows me there is applications and Applications. So I decided to try a git rm -r on Applications which also removed applications... However I reset back to an older state to rebuilt my repository manuelly and pushed it with --force. The result is that there are again these two directories Applications and application..... – bodokaiser Dec 09 '12 at 15:51
  • @kyogron You could `git reset --force` to the commit before your modification, and try `git mv` again. – VonC Dec 09 '12 at 15:54
  • Okay tried this too and failed. I also tried to rename Applications to apps and commit, rename apps to application and commit and then it is has changed somehow back again. I think the +hfs is not saving the rename properly. How ever will handle this another time. Thank you for your tries – bodokaiser Dec 09 '12 at 16:14
  • I found a safe solution for the problem. Create a new branch and checkout this new branch. Then delete the .DS_Store file in the directory of the corrupted directory and rename it to new name. Then remove wrong directory in the repository (you can view them with git ls-files) and commit this change. Agains remove the .DS_Store and now rename the directory to the lower case name you want with git mv – bodokaiser Dec 09 '12 at 18:01
  • @kyogron excellent. I have included it in the answer for more visibility. – VonC Dec 09 '12 at 18:19
  • thats great. I unfortunately forgot to add that you have to remove the whole repository and reclone it from the origin. Do not know why this is so awful but however there where some files missing in the working stage after merging even they where in origin... – bodokaiser Dec 09 '12 at 18:25