简体   繁体   中英

Can I remove these 2 commits in GIT?

Having the structure shown in the picture, Can I delete the commits 0ec08281 and 21736a48? I think that maybe I could do it using rebase but I'm afraid of deleting also the last commits.

历史

Edit: I forgot to mention that the commits were pushed to the remote server. However now I'm the only one with access to that server (at least up to now) so there is no chance of messing the source code to other people.

You can use an interactive rebase (using the -i) argument, and delete the hashes of the commits that you wish to remove.

Providing you have not pushed your changes to a shared repository yet. Find more information here: * http://git-scm.com/book/en/Git-Tools-Rewriting-History *

eg git rebase -i 22782e08

That should be fine, remember any commit id that is deleted in the interactive script window will be removed, if you wish to abort, delete ALL the commits from the script. There will be on screen instructions regarding this.

Out of interest, why are you deleting them? The graph looks fine to me, if you're doing it for tidiness reasons.

Interactive rebase is not a good idea if you have pushed the changes, you'll be rewriting history.

A better way is to revert the changes you don't want

git revert 22782e08

etc

This will create a new commit that undoes the changes in the commit you are reverting.

This is better, because it doesn't change history, but undoes the changes.

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