I am using git GUI (together with Git bash). Now, I know if I want to ignore files for git I have to put them in a .gitignore file.
1)I have come to know that git in windows does not create a .gitignore file for you and you have to create it yourself. Also git GUI won't do that. Is this correct?
Now my special situation:
I made a mistake in the beginning of managing this project and together with my .c and .h files I also tracked another file (let's call it "shouldnottrack.file"). This file is generated by the build process, so in principle should not be tracked.
But I did it and it was included in the commits (staged, commited etc).
Now, I want to untrack this file.
I have done it temporalily by doing git checkout -- shouldnottrack.file
but this works only once
How can I untrack this file? (GUI, command, any method ok)
If I include this file in the .gitignore file, will git untrack it automatically?
If the file is not shown in the Unstaged Changes Window in the main Git Gui window press the Rescan Button. Then to click the Stage Changed button. Then a Confirm window will be shown to add the untracked file. Untracked means Git sees a file that it didn't had in the previous commit.
Visual Studio 2019 | Visual Studio 2022 For files that aren't tracked by Git, you can use a . gitignore or exclude file. For files that are tracked by Git, you can tell Git to stop tracking them and to ignore changes.
You have to add it to .gitignore
and remove it from the git repository so that it stop to track it.
.gitignore
has no effects on file already tracked.
You have 2 possibilities depending if you still want to keep your files in the working directory or not:
git rm
.git rm --cached
.Then, commit this file deletion.
Not sure about your first question as I exclusively use the Git CLI however for your second question try this:
'git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE' \
--prune-empty --tag-name-filter cat -- --all```
Replacing PATH-TO-YOUR-FILE with the actual file name you want to scrub from the history. You should see something along the lines of:
Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (266/266) Ref refs/heads/master was rewritten
If it was successful - After this if you have already pushed to your remote you will need to do a `git push --force` to overwrite it. Security settings on the branch may deny the push.
Finally for your last question to prevent this happening again add the file in question to your ignore file and git will prevent any tracking from occurring.
The above answer will work however I strongly suggest this approach if the data was sensitive - ie passwords, ssh keys etc as the files will still be in history.
You can read more here https://help.github.com/articles/removing-files-from-a-repository-s-history/ and here https://help.github.com/articles/remove-sensitive-data/.
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