简体   繁体   中英

Remove some commits in GIT

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

在此处输入图片说明

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM