Committed PNG files to Git on Windows broke %PNG\r\n header - windows

I added lots of PNG files to a Git repository on Windows, unfortunately with the setting text eol=lf to not commit Windows line breaks.
The problem is that the PNG header must be in the form %PNG\r\n and now all PNG images are in Git with the header %PNG\n and cannot be displayed like that.
I tried adding this line to .gitattributes:
*.png binary
But the files, although correct in the working directory, still show up as unchanged and git add does nothing.
I managed to fix single files with checking out the broken version and editing it manually but I hope there is a less tedious way.
How can I fix my repository without modifying the individual files?

I managed to solve it myself while writing down the question:
Remove all PNG files from repository but keep the working copies:
git rm --cached **/*.png
Add them again
git add **/*.png
Ready to commit!

Related

Where to put .gitignore in local Windows repo [duplicate]

This question already has answers here:
Ignore files that have already been committed to a Git repository [duplicate]
(21 answers)
Closed 6 years ago.
I'm trying to create a Github repository for a friend's project (a video game), but can't get the .gitignore file to work properly.
I'm attempting to ignore directories that contain image and audio files, as these aren't best stored on Github.
I've placed a .gitignore file in the root directory of the repository, and put rules in it to ignore the aforementioned directories, but can't push the repo to GH without pushing several thousand PNGs and WAVs.
Do I need to put my .gitignore inside of my .git folder?
Do I need to reinitialize the repository since I added the .gitignore after initialization?
Here is the content of my .gitignore
sprites/images/
sound/audio/
There are two ways to solve this:
Put two .gitignore files into sprites/images and sound/audio, both containing just .. The dot matches the current directory and will therefore exclude the two directories.
Put one .gitignore into the root of the project, and add /sprites/images and /sound/audio (each one in it's own line). If you don't put a slash at the beginning, you will also exclude directories like src/sprites/images.
If you want a repository/machine specific gitignore that can not be put under version control, you can add your ignore lines to .git/info/exclude. Paths there will be relative from the project root (like in 2.), but as you can not check this file in and it does not get overridden when pulling, so you can add your personal ignores there.
Git will immediately detect the .gitignore file and any command issued from now on will respect it. Of course, you can commit it too, so every developer has it as well.
If you have already checked in those files, you can use git rm (note that this also removes the files from your disk!) and commit afterwards.
Or, if you want to remove the files from the entire history to shrink your repository size, you can rebase them out. Never rebase and force-push if you don't exactly know what this means for everyone else in the project. It will cause all changes that are not in your local repository (at any other developer and at GitHub) to be overriden.
git rm -r --cached .
git add .
git commit -m "Appropriate message"
git push origin branch_name

.gitignore is not working on Windows

I used to develop on linux environment, but now I need to write a git project on "windows" os. I need to ignore a directory from where the git is initiated.
like folder/.git/, now I need to ignore /folder/project/bin/*. So I have added .gitignore file on folder/.gitignore using both text pad and Visual studio.
.gitignore file contents are
/project/bin/*
Now, I expect git status should not show /project/bin folder.
Note, I have tried other ways too, but it seems that git is considering the .gitignore file as a general text file or so.
Just a guess, but I suspect that the leading forward-slash is throwing something off. I'm not sure about the trailing star either (as I reference my own .gitignore files).
Your .gitignore should be this:
project/bin/
I frustratingly found the same issue. I couldn't seem to ignore folders, but files were OK. My issue started with folders that contain spaces. All the combinations I could find after a searching (full directory path, trying to ignore case, escaping the spaces, etc) didn't resolve it.
I had to remove spaces in directory names, then I was able to ignore files.
I tried it on WSL (Windows sub-system for Linux - git was already installed), no problems.
Then reading more, I realised that if files are previously tracked, then the .gitignore won't work. I tested it by deleting all the files in the directory, then adding the directory to .gitignore path/to/my_files/*.csv (in my case I'm ignoring data in .csv files) and doing a commit then push (good job this is just dev).
After that worked, I was able to use git rm -r --cached ./path/to/my_files/ to un track all the files in another directory rather than cutting and pasting them back (Thanks to this answer)
So:
Un-track all the files
Add the directory in .gitignore (In windows it wasn't case sensitive)
add/commit/push as normal.

Git clean single untracked file

I would like only a certain file to be untracked unlike
git clean
which will remove all untrack files. Thus what is the best way to do that.
Thanks.
Delete it (with rm or whatever facility your OS provides for deleting files).
If you want to keep the file, add it to the repo's .gitignore file, and Git won't try to track it anymore.
#mlpadi answer is correct as well. In this case though what I was looking for was
git clean -f {dir_path}
It helped me clean the files from that 1 folder it was complaining about

Untrack all files on git

In the move from C9 to hosting on my Macbook via SSH, I've had to re-download Kohana and change some other things just to get my site working; I don't want those to be committed. Is there any way to untrack all tracked files so only future changes are committed? Or is there something else I should be doing?
I'm on a Macbook running Mountain Lion with Apache and PHP turned on.
Even simpler:
cd /root/directory/of/your/local/repo
git rm --cached -r .
^^^
(space - dot)
Even even simpler:
git clone url/for/Kohana /different/local/path
git rm --cached File
Will delete the file in the index, so it will no longer be tracked, but won’t physically delete it. This will untrack the file only for current branch
[OR]
Use this git command. After you do this, git stops checking the file for possible modifications.
git update-index --assume-unchanged <filename>
At any time, you can track again by setting --no-assume-unchaged flag
git update-index --no-assume-unchanged <filename>
But these command do not affect the remote repository.
I'm not exactly sure what you mean by "untrack all tracked files so only future changes are committed". As you need to track files so they can be committed.
If all you just want to do is not track Kohana and the other downloads, then just remove them from your working directory using git rm --cached <file> or even better create a .gitignore file.
There are many helpful posts on stackoverflow to assist you with creating a .gitignore file for your project. By using this, you can exclude an entire folder easily.
For Mac, it would also be helpful if you could see hidden file as the . file is hidden. This page shows you how to see hidden files on Mountain Loin - http://www.mikesel.info/show-hidden-files-mac-os-x-10-7-lion/

Change case of a file on Windows? [duplicate]

This question already has answers here:
How to make git ignore changes in case?
(6 answers)
Closed 10 months ago.
There are a couple of files in our git-controlled codebase that I'd like to rename. Specifically, I just want to change the case of the file, so that sourceCode.java becomes SourceCode.java, for example. The catch: I'm on a Windows box, and the filesystem thinks those are the same file name.
How can I get Windows and Git to recognize that change and check it in?
The change of the file name should not be ignored, but committed to git.
To rename the file you can use the standard git mv command.
Since Windows treats files with only changes in case as identical, you have to pass the -f option to force a rename:
git mv -f name.java Name.java
If instead you want to ignore case changes, have a look at the question
How to make git ignore changes in case?.
If you are on a FAT file system your only choice is to do a two stage rename:
Rename sourceCode.java to anything.you.like
Rename anything.you.like to SourceCode.java
Back in the days when we used Perforce we had exactly this problem and this was the only solution we could come up with.
The following steps allowed me to change the case on Windows:
Add ignorecase = false to [core] in .git/config;
Move the files you are going to rename out of your project directory;
Add the deletes to the index;
Move all files back to their original location and change the case of the files and/or directories;
Add all "new" files to the index;
Remove ignorecase = false added at the first step.
This way you have a single commit that contains the rename and it makes it easy to change e.g. an entire directory.
In my opinion one simple way is missing. You can do this for a single file, a specific directory or even the whole repository. Just rename your files in any way you like before and than execute these commands:
git rm --cached <file name or directory>
git add <file name or directory>
If you want to affect also the sub-directories, you have to use the -r flag:
git rm -r --cached <directory>
git add <directory>
Be careful. Doing this can lead to changes that are impossible to merge. Git gets confused when merging on Windows because it can't decide whether the old Uppercase name and the new lowercase name are the same file or not (for Git they are not, but for the filesystem they are). To merge you have to do some manual workaround like deleting the files before merging.
See Git rebase issue with files of same name but different case
I'm not sure if this issue is worse than having an unconventionally-named file in your project for ever and ever, but it is worth knowing about if there are lots of users with lots of branches which will all need to be merged eventually.
With NTFS (or FAT), a single git mv command does not solve the problem.
This question shows a technique that works:
git mv and only change case of directory

Resources