Is it possible to fix Windows altered case of file names with pull from remote git repo? - windows

I have a problem where a Windows file restore changed the case of some file names. This causes a trainwreck with some projects.
Fortunately these projects are pushed to remote git servers. The remotes are up to date with origin/master, and cloning the projects is a solution. The only problem with that is the time-consuming task of replacing git-ignored files and dealing with other updates.
An ideal solution would be to pull down all files from the remote, overwriting the files in the origin/master. Is this possible? How do I force a pull down or merge, even though they are already a match. I want to keep it that way, just use git to rewrite the correct file name cases.
git pull or git pull -f results in Already up-to-date.

First, set git to be case sensitive. By default this was set true to match Windows:
git config core.ignorecase false
Check the list of changed-case file names Windows messed up. At the very least, this is your list of files to fix:
git status
Now, delete the files and folders that are messed up. Do not delete git ignored files! Files in .gitignore must be fixed the hard way.
Now, get your deleted files back as they were before Windows changed the case:
git checkout .
Yet another reason to quit Windows.

Related

Cannot git checkout master: invalid path '?'

After an "unsuccessful" git pull on my local master, an error prevents to switch back to master:
C: repo_folder> git checkout master
error: invalid path '?'
The ? must be because it is a keybase repo.
From another branch where I checked out some files of the last commit:
C: repo_folder> git diff origin/master --compact-summary
"\004" (gone) | 1902 ---------------------------
some irrelevant stuff | (num) -
The removed file "\004" (that was never present in my local) seems to come from some Mac OS (someone might have opened a csv and a temporary file was created when that user did the commit and pushed?).
observe that the file that is marked as (gone) is to be removed by git
the problem is that the filename has characters that are not compatible with the Windows file system and that the file never existed in my local Windows repo.
If I clone from a Linux platform, I can checkout to master with no problems. However, in Windows, there's no way back to the master branch.
Any ideas on how to solve this issue? (already tried some posts with no success)
I can't really understand how it comes git doesn't even allow me to checkout to master. Should I file a bug report?
Alternatively, perhaps I could create a new master branch and get rid of the current one.
EDIT
A clone from Linux helped to identify that the file ? was actually there.
This could be checked directly from Windows as well by using the command: git ls-tree origin/master (which was showing the original problematic name "\004")
The accepted answer includes the case where you want to save the content of the file, while in my case I only wanted to get rid of it. So in my case, I have just deleted the file from Linux, committed and pushed the change, and did a git fetch origin master:master to fetch my local master with being checked out in another branch (as I was not able to checkout to master). This finally did the trick and I could checkout to master.
Hope this clarifies to someone with a similar problem.
? (or maybe it's EOT) cannot be used as a filename on Windows. The file will have to be deleted or renamed. You can do this most easily by cloning on a system which does allow ? and making the fix.
If you only have Windows, Fixing Invalid Git Paths on Windows offers a method of renaming the file without checking it out. In brief...
git checkout origin/master -f to get the checkout without the problematic file.
Make a branch.
Add and commit the "deleted" problematic file.
Use git ls-tree HEAD^ to get the ID of the problem file.
Use git cat-file -p <ID> to get the content of the problem file.
Put the content into a new file.
Add and commit.

git on Mac sees files I havent touched as modified and they also appear as staged already

I am seeing strange behavior on Mac with git. I dont see this happening on Windows. Using git v 2.19.1 on mac and 2.18.0.windows.1 on windows.
I work in a crossplatform team, so some of us use Windows, others use Mac. I use both.
Here is the scenario I see:
I work on my feature branch for few days and like to make sure I update my branch with latest changes on remote so I always work on most recent version of remote. So, I daily do following to reduce chance of conflicts and stay on most recent version:
git checkout develop
git fetch origin
git merge origin/develop
git checkout my-feature
git merge develop
Once that is done, I apply my changes to my-feature branch but I notice that git behaves very strangely on Mac. Here is what happens:
I added some changes
I did not stage anything yet, so no git add . was issued
I do git status and I see lots of files as if they got modified and staged by me even though I did neither modified nor staged them.
For example, git status shows my .gitignore file now as:
me$ git status
On branch my-feature
Your branch is up to date with 'origin/my-feature'.
Changes to be committed:
new file: .gitignore
On Windows, this does not happen and since I did not modify this file, it will not show in git status at all. My modified files show as needed to be added which is how it should behave.
Why would files I never touched be viewed by git on Mac as somehow modified and staged?
In mixed dev environments (like I work in also) I see this behavior when 'line endings' are mismatched. The best way to solve this is to update your .gitconfig file.
I encourage everyone on the teams I work within to add the following to their .gitconfig file. You can add a .gitconfig to each repo, just like a .gitignore, and/or each developer can set it within their git global config file.
[text]
eof=lf
There are different options, but the key is for the whole team to use the same line endings when committing & pulling.
Here is my gitconfig, per the request below.
[User]
name = Ben Horgen
email = xxx#xxxxxxxx.com
[text]
eof=lf
[core]
autocrlf = input
[pull]
rebase = true
[push]
default = simple

Backing out staged changes in Mercurial on a Mac

I just cloned an hg project that is typically maintained by Windows users (I'm an a Mac). I just did an hg add . and got a bazillion of the following messages:
adding out/blah
adding out/meh
adding out/fizz
adding out/buzz
...etc.
I do not want anything under out/* getting committed & pushed! So I added the following entry to .hgignore:
out/*
And then re-ran hg add .. Have I successfully prevented all this cruft living under out/* from being committed & pushed to the remote repo? If not, what else (specifically) do I need to do, and in what order?
First, check with
hg status
which files were actually added (you can also use hg status -a to restrict yourself to added files). Unless you removed them, the files in out still remain added. In order to get rid of them, use:
hg forget out
Then use hg status or hg status -a again to verify that they are no longer part of the planned commit.
I'll also note that out/* will also exclude any files in subdirectories that are named out, e.g. foo/out/bar.txt. To ignore only files in the directory out at the root, use the following line instead for your .hgignore:
re:^out/
The re: prefix will use regular expression matching instead and ^out/ will match all paths that start with out/.

Git status shows file twice but different case

I tried to do a search for my issue and the closest thing that I could is this.
git Status Shows Same File Twice - But with different path slash styles
But it doesn't seem to be the same issue I have.
I was doing a commit and noticed that the same file was listed twice but with different case. For instance, Directory/resource.h and Directory/Resource.h. Now there is only one file in the directory resource.h. If I look at the file through Git Extensions they look exactly the same. There doesn't seem to be another hidden file, there is only one file.
So I tried to fix this by removing the resource.h file, committing, and then adding the file back and recommit again. Only one file showed up as added. I thought I fixed the issue, but now if I try to checkout a different branch I get the following error.
error: The following untracked working tree files would be overwritten by checkout:
Directory/Resource.h
Please move or remove them before you can switch branches.
Aborting
Done
I don't really have any idea what to do from here, I've only been using Git for a few months and I haven't had to do anything more complicated than merging branches and pushing and pulling.
This can happen in Windows if you have a repo with ignorecase = false and rename a file without using git. To fix, this should work
git mv -f Resource.h resource.h
git commit -m 'fix case'
and this should prevent it from happening again.
git config core.ignorecase true

Git (windows 7) won't add directories, but adds files files typed explicitly

trying to find an answer to this, have seen it hinted at, but no solution.
Not entirely new to git, but haven't used it in a few months... this is my first time using it on windows. using git bash.
I have a cake PHP site that I want to add exluding any cache files my .gitignore file contains only:
app/tmp/*
Here is the most basic thing I have tried:
git init
git add .
git commit
I get a message on commit saying there are untracked files - all files and dirs at the root directory.
git status
gives me the same message.
However, if I type
git add .htaccess
it stages the .htaccess file.
Also, if I do:
git add app/.htaccess
It will add that file too.
I have also tried
git add app/*
no luck.
Thanks in advance.
The files aren't ignored, because otherwise you would be forced to do a git add --force afile.
However, you might want to check GIT_DIR and GIT_WORK_TREE environment variable, and see if they reference another repository, which could explain the discrepancy between the index and what you think is your working tree.

Resources