Jump to content

Removing one change from a commit


proggR

Recommended Posts

Apparently I made a commit a while back that included some vital login information that shouldn't have been committed. Obviously the username and password are in the process of being changed but I still need to remove that change from the history. I have the commit numbers but how can I delete the changes to the history without affecting the rest of of the commits? The file in question was included in a commit that also changed another file. Those changes I would like to keep, just not the changes to the settings file. I've been searching for an answer but I'm not overly familiar with git except what I use in my day to day development.

 

Any help or guidance would be appreciated. thanks in advance.

Link to comment
Share on other sites

If the commit has only ever existed locally, then you're in luck.  If the commit was pushed anywhere (anywhere!) then, depending on where the commit may have spread to, life could be painful.

 

So, before offering solutions, exactly where is the commit now? Just in your local git repo, pushed to a super-tightly-controlled remote, only wherever your colleagues (if there are any) might have it, or potentially anywhere?

Link to comment
Share on other sites

Its been pushed to a remote repository where only my colleagues have write access to. It is possible for anyone to clone it with read only access, but only we have access to write to it. This mistake was made almost a month ago and there are tons of commits that have been pushed to the repo since then by both me and my colleagues.

 

I've been reading about rebase but I don't really understand it well enough to find a fix. One fix I've come across is to checkout a new branch based on the bad commit, remove the file that's bad, checkout the main branch and rebase from the new branch. I've tried this just not but it seems to come into a lot of conflicts that I don't understand why they would exist. Also, I don't want to delete the file, I just want to undo the changes that were made to it during that commit.

 

I hope this helps. The developer that usually takes care of anything git related is in the middle of preparing for an update and doesn't have time to sort this out and since its my fault I've been tasked with the cleanup. Thanks again.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.