Tumgik
#troubleshmup: git
troubleshmup · 7 years
Text
pls ctrl z
Being at an internship has made me forgetful about my commits. When I do remember them, I either have an obscene amount of features I honestly should’ve been tracking all the while or literally one line change. I feel like the few times I have been so great about writing great commit (okay, great might be exaggeration), has always been the times I’ve been struck by the horrible, heart plunging feeling that “oh no, those all had my keys... a;lsdkfjal;skdjf” Well, having experienced that godawful moment more than once, I decided to actually take notes on what to do when I’m not in a panic-driven state (does wonders for clarity, I’ll have you know.) There’s undoubtedly a wealth of very informative guides on the topics, but here’s my quick-start to just get things going:
This will affect all your local branches (does it affect remote? I don’t know, I should find out), so clone the project, published security issues and all, just in case this doesn’t lead to calmer waters. In terminal, or whatever you drive:
$ git filter-branch --force --index-filter \ 'git rm --cached --ignore-unmatch */Constants.cs' \--prune-empty --tag-name-filter cat -- --all
In bold is the the file you’re trying remove from the record. If you simply had a traitorous ‘.env’ file, you could just write *.env. In this case, I have many .cs files and wanted to target a very specific one buried in a folder, hence the path with the wildcard. Now that I think about it, I didn’t have anything else in the folder, so I wonder if I could’ve just put the folder name.
I honestly don’t know what black magic flag invocation this is summoning, but the important thing is it’ll probably scrub your commit history clean. Of course, still change all that information that you just leaked but don’t just leave your spills lying around, right?
Anyway, you’ll hopefully get a lot of lines with the SHA tags (I don’t know if that’s what it’s called) saying rm your-file-name, and it’ll finish with a list of all your branches rewritten. If it ends with warnings instead about how they’re all unchanged though, go back and fix your file path (the part that’s */Constants.cs in the example above).
ALSO, after you’ve done that, BEFORE YOU COMMIT AGAIN and relive the nightmare, please put your sensitive files into your .gitignore. Go on, do it right now. 
TLDR:
$ git filter-branch --force --index-filter \ 'git rm --cached --ignore-unmatch *.env' \--prune-empty --tag-name-filter cat -- --all
add file to .gitignore
0 notes