Changing case of Folder via Git bash on Windows - windows

I need to change the case of folders and files. First thing I tried was renaming the folders, but Git didn't pick up the changes. So I tried using git mv -f controller Controller but it says :
fatal: renaming 'application/classes/controller failed: Permission denied
I have tried setting the global ignorecase flag:
git config --global core.ignorecase false
But it still doesn't work. Some people have suggested to move the folder out of repo, delete, then re-add but would this change get picked up when other people pull the repo? Is there anything else I could try?
Edit: It works for files but not folders.

In summary of the comments, you'll have to rename the directory via a intermediate temporary name. E.g.
git mv controller Controller-tmp
git mv Controller-tmp Controller
I think this has to do with the fact that the MinGW implementation of rename(2) does not support this operation. See this thread, the MSDN docs on the CRT rename implementation and those of the MoveFileEx function.

Make sure to close Visual Studio and any Windows Explorer folders related to that path.

Make sure to add the changes to index after rename folder with intermediate folder as below.
git mv oldfolder newfolder
git add -u newfolder
git commit -m "changed the foldername whaddup"
Reference

I could not resolve this apart from performing the following
Branch from commit before folder name case changed, as a temp branch just to resolve this issue.
Cherry picking commits in order resolving folder case name changes before committing.
Reset old branch this new temp branch final commit.
Remove temp branch.

Related

Folder capitalization not changing on branch switch

I'm working on a python project and want to rename a (package) folder to small letters, let's say from Myackage to mypackage. As git is case-sensitive and Windows is not, I followed the solutions taken from here and espacially here.
My procedure was as follows:
git mv Mypackage tmp
git mv tmp mypackage
git commit -m "Change capitalization of package name"
This changes the folder Myackage to mypackage with success (for both, git and Windows). But if I switch to another branch, I expect the folder to change back to Mypackage (with capital letter!), as it was before. Background is, that all the imports of the package are also case-sensitve in python and i need this renamng acompanied with adaptions of the imports.
I've tried both, core.ignorecase set to true and false, but no matter what I try, if I checkout an older branch, the folder remains in form of small letters (mypackage) and I run into issues within python.
UPDATE:
I've set up a small example with only one Folder and one file and could succesfully change the capitalization of the folder. It also shows the desired behaviour, that upon branch switch the capitalization of the folder in Windows changes, yet still this won't work for my python project.
Could it be, that, e.g., submodules, play a role here?
UPDATE 2:
I've checked the case sensitivity attribute for both cases via:
fsutil.exe file queryCaseSensitiveInfo .
Both folders claim, that case-sensitivity is deactivated. Still for one project folder name capitalization changes, but for the other folder not.
The attribute case sensitivity is available on Windows 10 but after April 2018 Update and only affect the specific folder to which you apply it. It isn’t automatically inherited by that folder’s subfolders. However, if you use WSL to create folders it's enabled by default and available in that way to Windows. [1]
Although you can use the Git Unite [2] tool to match the case of the current folders with the git index.
If you use the rename approach, try using it with git commands like in "Rename files and folders with git"[3]
git mv foldername tempname && git mv tempname folderName
I found a way to reproduce your behavior :
if my CaSeD folder contains some extra files (untracked files for example), git will not change the case of my folder name when I jump between commits.
Is this the case in your setup ?
If this is your issue : you could go with a post-checkout hook, which forcibly renames the folders according to what is stored in HEAD after a checkout.
One way to get the full list of paths to directories from commit HEAD is :
git ls-tree --name-only -d -r HEAD
If you match this list with a similar list extracted from your local file system (ls -r ? find . -type d ? some python function from os.* ?), you can spot what folders need to be recapitalized.

Touch all files in a git repo so git thinks they are changes

I need 'touch' (I think) all files in my git repo (lots of files) so that running git status will have them as modified (and then I can add and commit them). I need to do this because our in-house tool uses the files from a git commit to generate a report ... which I've been asked to do
In posix environments I think I could just touch a directory and go from there.
I don't think that's possible because git detect that a file change if the content of the file changed. Touching the file will have no effect (even on unix).
Perhaps changing the permission on the file could be a very dirty solution but I'm not even sure of that and that's if you find a new permission that don't introduced some bad side effects!
The better solution is to update your reporting tool.
And being obliged to commit changes for ALL files to trick your tool and dirty your history is in my opinion a very bad idea...
If you were asked to "generate a report with all files" does that mean list all files in a commit? Cause that's easily done with something like a git ls-tree -R HEAD
I had a demo repo that had a bunch of files in it, that had commit messages that I didnt want showing up in the demo - and to be clear, the repo was "garbage", in that it was just basically a dump of files to demonstrate a folder structure.
That having been said, one way you could do this is to
create a new temporary folder in your repo, for example "ez"
move all the files of the repo into it, e.e. "$ mv * ez"
commit that locally, the do the reverse and move them out again
"$ mv ez/* .; rmdir ez"
That would show all files as having been changed. For my purposes, I then committed that change too, and pushed it up to my demo repo.

Dropping files inside gitignore path onto Xcode

Each time I try to add a file to my resources which is in gitignore Xcode keeps telling me
"The following paths are ignored by one of your .gitignore files:
res
Use -f if you really want to add them.
fatal: no files added"
So I add my resources by removing the res folder from gitignore, then dropping the file onto Xcode, and finally adding the res folder again to gitignore and removing any stage changes.
Is there a better way to do this procedure?
I'm keeping my res folder in gitignore because of too many binary files, otherwise the git folder would start to increase its size astronomically
You can add them by using the --force flag on add:
git add -f res/foo
git commit -m "more resources"
(or by using wildcards, e.g. git add -f res/*)
Bonus tip: If you want to list the files that have been committed even though they match gitignore, you can do
git ls-files -i --exclude-standard

How to get Git on Windows to ignore symbolic links

I can't get this to work.
I have cloned a repository that has a dummy file (named src): /path/src.
On Windows I have created a symbolic link: mklink -d /path/src /otherplace/src (but I of course had to delete the dummy src file first).
In both my .gitignore and .git/info/exclude I have
/path/src/
/path/src
path/src/
path/src
And I have tried
git ls-files -s | gawk '/120000/{print $4}'
git update-index path/src/ --assume-unchanged
but I still get:
error: readlink("path/src"): Function not implemented
error: unable to index file path/src
fatal: updating files failed
I have tried all these other suggestions. And even this doesn't work.
Any ideas?
You can do a checkout ignoring this single file like this:
git checkout HEAD . --no path/src
The .gitignore file only works for adding stuff to the index. Even a modifications on files commited before adding it to the .gitignore are not ignored.
I know this is late, but I ran into this issue.
In my case, I apparently had checked in my symlink at some point. So no matter what I did, .gitignore would not work (I think that is what Alexandre was getting at).
REPAIR:
Remove all symlinks
See if git now thinks there are deleted files to commit.
If so, then go ahead and commit the deletions.
Now you can re-add your symlinks and .gitignore should work.
Here are my steps for this issue, similar, but a bit different from other answers.
Let's say I had a folder .fvm contain file.json and flutter_sdk(link) that all commited in git before, then I want to ignore out flutter_sdk.
Add .fvm/flutter_sdk and .fvm/flutter_sdk/ in .gitignore.
Cut .fvm/flutter_sdk out to other place than the repository.
git add . and git commit ....
Paste back the link.

Case typo on path in msysgit

I went out to my github repo and discovered that I had inadvertently added files to msysgit with a typo. Instead of adding files to a directory called "Domain", I added them to "DOmain".
I tried git mv, but the path is case-insensitive in Windows and the move fails.
What's the best way to resolve an issue like this?
mv to something else, like "tempdir", and then mv back to the proper capitalization?
Go back in history (git checkout someHash), create new dir with proper case, checkout the files from the wrong commit (git checkout someWrongHash someFiles), commit them, and then, reset HEAD to the new commit.
(And next time, don't torture youreslf with git on Windows ;) )

Resources