Page MenuHomeSealhub

X3: I've already pushed the changes, how to undo them and create a diff?
Updated 503 Days AgoPublic

If you accidentally pushed your changes to the repository, you can undo those changes and create a diff for review using following steps. Assume this state of the repository:

01ccb2a6 (HEAD -> main, origin/main, origin/HEAD) my unreviewed changes 3 # ← whoops! pushed to origin/main!
8f808730 my unreviewed changes 2
3bc05b39 my unreviewed changes 1 
99c9f590 Landed diff D1234   
126291f7 Landed diff D1235
4e443496 Landed diff D1231
...

1. Create a new branch that points to the latest commit:

$ git checkout -b my_changes
01ccb2a6 (HEAD -> my_changes, main, origin/main, origin/HEAD) my unreviewed changes 3 # ← whoops! pushed to origin/main!
8f808730 my unreviewed changes 2
3bc05b39 my unreviewed changes 1 
99c9f590 Landed diff D1234   
126291f7 Landed diff D1235
4e443496 Landed diff D1231
...

2. Find the ID of the base commit.

That is, the last commit before your changes that you want to submit for review.

01ccb2a6 (HEAD -> my_changes, main, origin/main, origin/HEAD) my unreviewed changes 3
8f808730 my unreviewed changes 2
3bc05b39 my unreviewed changes 1 
99c9f590 Landed diff D1234    # ← that's the one we're looking for
126291f7 Landed diff D1235
4e443496 Landed diff D1231
...

store it in a shell variable:

$ PREV_TIP=99c9f590

3. Move your local main (or master) branch to that commit

$ git branch -f main $PREV_TIP
01ccb2a6 (HEAD -> my_changes, origin/main, origin/HEAD) my unreviewed changes 3
8f808730 my unreviewed changes 2
3bc05b39 my unreviewed changes 1 
99c9f590 (main) Landed diff D1234  # ← main moved here
126291f7 Landed diff D1235
4e443496 Landed diff D1231
...

4. Checkout the newly moved main (or master) branch

$ git checkout main
01ccb2a6 (my_changes, origin/main, origin/HEAD) my unreviewed changes 3
8f808730 my unreviewed changes 2
3bc05b39 my unreviewed changes 1 
99c9f590 (HEAD->main, HEAD) Landed diff D1234  # ← main moved here
126291f7 Landed diff D1235
4e443496 Landed diff D1231
...

5. Enable dangerous changes

We're about to push the new branch, overwriting the state on the server. This is forbidden by default, but we can temporarily enable it by using "enable dangerous changes" on that repository.

Go to the repository page and click on ActionsManage+Repository

image.png (735×787 px, 90 KB)

And then click on "Allow dangerous changes"

image.png (725×1 px, 107 KB)

6. Push your local changes to the main branch

$ git push --force
01ccb2a6 (my_changes, HEAD, origin/HEAD) my unreviewed changes 3
8f808730 my unreviewed changes 2
3bc05b39 my unreviewed changes 1 
99c9f590 (HEAD->main, origin/main) Landed diff D1234  # ← main moved here
126291f7 Landed diff D1235
4e443496 Landed diff D1231
...

7. Disable dangerous changes in the repo

See point 5

WARNING: It's super important to disable dangerous changes asap!

8. Move back to the my_changes branch and create a diff

$ git checkout my_changes
$ arc diff main
Tags
None
Referenced Files
F630705: image.png
Aug 9 2023, 07:33
F630710: image.png
Aug 9 2023, 07:33
Subscribers
None
Last Author
migueldar
Last Edited
Aug 15 2023, 01:04

Event Timeline

kuba-orlik edited the content of this document. (Show Details)
kuba-orlik edited the content of this document. (Show Details)
kuba-orlik edited the content of this document. (Show Details)