Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

git - Remove a specific commit from history keep all the commits


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you are a single developer (i.e. not sharing a repository with anyone), you can use the Git Rebase -i mechanism. Check out the resources below:

Then replace the pick or squash command that was presented in the material with the command: "Drop", it will remove the Commit you indicated

However, if you are sharing code with someone, and you perform a git rebase, this will affect other people's repositories. You will need to warn them about this!

If these are not critical files, i.e. files that should not be outside your computer at all, and their existence in the repository is not dangerous for some reason (e.g. compiler generated files, operating system specific files, etc), you can do a git revert:

Git revert {id-sha-commit}
Git revert 706d92d43227dbb4a229aa157d197ba3c1f4a627

Git revert will reverse the changes, that is, instead of adding, it will remove them.

Then simply execute git push

In other cases, (Working on a shared repository, no free modification) you already have to use more advanced tools like Repo Cleaner:

Or become more familiar with the Filter-Branch command (quite an advanced practice)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...