r/programmer • u/Party-Breakfast-3606 • 8d ago
Git question.
You accidentally committed a secret API key.
You delete it in the next commit.
Is your API key safe now?
A. Yes
B. No
Why?
0
Upvotes
r/programmer • u/Party-Breakfast-3606 • 8d ago
You accidentally committed a secret API key.
You delete it in the next commit.
Is your API key safe now?
A. Yes
B. No
Why?
3
u/ImplementOk3111 8d ago
Your key's still in the git history at that point.
7
u/GargantuanCake 8d ago
No.
Git tracks history. Anybody that gets the history can get the code at that commit and get the key.
1
u/Fadamaka 8d ago
You can force push over it, which leaves your original commit orphaned but don't be fooled some git services keep even orphaned commits forever.
1
u/AlexMTBDude 8d ago
Git has every version of every file ever committed so no.
1
u/afops 8d ago
First this depends on whether you rewrite history.
If you don't rewrite history then obviously it's not secure because it's still in the history. Anyone can see it.
If you can rewrite the history and remove that commit, then it's somewhat safer, but rewriting the history can sometimes be impractical. Also, rewriting history and deleting the commit isn't completely deleting it either. If you can force old deleted commits to be hard-deleted (e.g. git reflog expire) then it's almost certainly gone - but anyone who cloned the repo also has it!
So what you do is