开发者

GIT: how to remove a push that is in the middle of the working tree

开发者 https://www.devze.com 2023-04-12 07:39 出处:网络
Hi for ilustration purposes this is the tree at the server. (...) Change to E from user TTT Change to D from user LLL

Hi for ilustration purposes this is the tree at the server.

(...)
Change to E from user TTT
Change to D from user LLL
Change 开发者_如何学Cto C from user me
Change to B from user QQQ
Change to A from user TTT
(...)

I accidentally pushed C, how can I remove it from the main repository without affecting all the work my colleages pushed afterwards?

And if possible still keeping it as a local commit for myself.


The command you want is git revert. It creates a commit to cancel out another commit:

git revert <SHA1 C>

You can then push that to the main repository, and the change made by the commit will be reverted, while still leaving the commit itself (and subsequent history) intact:

- A - B - C - D - E - ... - C' - ...

To continue working based on it yourself, you can then revert the revert, or cherry-pick the original commit - hopefully on a local branch so you won't accidentally push it!

0

精彩评论

暂无评论...
验证码 换一张
取 消