2

I am new to Git, although I just managed to change file in my previous commit.

enter image description here

First commit in redbox let's call it R1 is the one with commited password. I made it accidentally, so I wanted to make change - just change the file where that password was. I managed to do it successfully, not from the first time.

So I the commits the "path" to my head - last commit is the green box. These commits are same as the red one, but without the password.

So everything is as I wanted it to be, but I want to remove the 3 commits that are in a red box, cause password is still there.

Can you tell me how to do it?

I understand that this might be a duplicate, but I have a picture so maybe it will help to understand better.

Andriy Kizym
  • 1,756
  • 2
  • 14
  • 29

1 Answers1

4

It looks like what you may be looking for is $ git rebase -i which will bring up the interactive mode for rebasing your commits. In interactive mode you can edit, squash, discard previous commits. This is a previous discussion about using interactive rebasing. source

This should be enough to help you clear away the previous commits that contain the details that shouldn't be public.

In the future you can create a .gitignore file that will tell git to ignore certain files, which helps greatly with privacy and security issues. You can find more about .gitignore files here.

In the future if this occurs you can easily erase a commit by using git reset --hard HEAD~1 which will bring you back to the commit before the head.

You can use git log at any time to find a specific id of a commit that you want to jump back to with git reset --hard <sha1-commit-id>, but be advised this will delete the changes at your local working level.

Community
  • 1
  • 1
Pippin
  • 1,066
  • 7
  • 15
  • Note that this way the commits still remain in the repository (unreachable by any branch, but they still do exist) until they get garbage collected. – 1615903 Nov 30 '13 at 11:06