Revert to commit and delete history Boîte de réception x #21782
-
Hello, Can you tell me how to delete the history? I have done this :
I would like do this
Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Ok, this is a little danger but i will try with an example. 1. This is the history of my master: 2. I want to delete the second commit with description “this commit need to be deleted”. The first thing to do is to get the commit ID of the previous commit, in my case the commit is “reset here”. You can get the commit id by the web UI: Or with command line:
with output:
Copy this value. 3. And now reset to this commit by paste that ID after the reset command:
this move the local history to this commit. 4. If you dont want the changes made by the last commit you can jump to the next step (point 5). Otherwise you need to create a new branch, for example called “helper”:
and cherry-pick the last commit, in my case the commit with description “i want this file on history” , using the commit ID of this commit:
(Remeber that the working tree need to be empty, so commit or remove the dirty files.) Now you need to merge this new branch into master, so checkout to master:
And merge:
You can now remove the “helper” branch:
5. Last step you need to force push to remote:
This is the last command you need to run. 6. If you follow the point 4 you have: Otherwise you only have: Hope this helps 🙂 -Gabriele-
|
Beta Was this translation helpful? Give feedback.
-
It’s perfect - it’s working. Thanks for all documentation. I found also this command : git rebase --onto master~1 master git push origin master -f Source : https://blog.hadrien.eu/2014/05/07/supprimer-un-commit-dans-lhistorique-de-git/ Thanks for support! Have a nice day |
Beta Was this translation helpful? Give feedback.
-
Hi Wabri, This was really very helpful, thank you. Regards, Shruti |
Beta Was this translation helpful? Give feedback.
Ok, this is a little danger but i will try with an example.
1. This is the history of my master:
2. I want to delete the second commit with description “this commit need to be deleted”. The first thing to do is to get the commit ID of the previous commit, in my case the commit is “reset here”. You can get the commit id by the web UI:
Or with command line:
with output: