ezyang / ghstack

Submit stacked diffs to GitHub on the command line
MIT License
657 stars 55 forks source link

Modifying existing PRs #268

Closed giovannizotta closed 1 week ago

giovannizotta commented 1 week ago

I just started using ghstack.

I have 2 PRs, one stacked on top of each other:

If I need to modify PR1, what is the expected process?

I imagined:

However, this did not work as expected, and I am a bit confused by the many branches that have been created and I am not sure how to solve this situation. Some guidance on how this usually works is really appreciated!

ezyang commented 1 week ago

In vanilla git, I recommend using git rebase -i. So git rebase -i $(git merge-base origin/main HEAD), 'edit' the commit you want, git rebase --continue, ghstack.

If you want to checkout PR1, and then you want to update PR2, you have to cherry-pick PR2 on top of your amended PR1. And it has to be the orig comimt; if you lost it you should use origin/gh/giovannizotta/XX/orig as the cherry-pick.

giovannizotta commented 1 week ago

Thank you for the quick reply @ezyang!

I'm a bit confused by the process. If I had to do this manually via vanilla git, I would:

  1. checkout PR1, make changes and git commit --amend
  2. checkout PR2, rebase on top of PR1
  3. repeat rebase for any PR on top of PR2

How does this process look like with ghstack? If I have to cherry-pick PR2 on top of PR1 any time I make a change and fiddle with open PRs it sounds like more work than the vanilla git solution. Am I missing something?

giovannizotta commented 1 week ago

Now I understand what you meant by git rebase -i. I was missing the fact that you have to checkout the top-most PR in the stack, instead checking out the commit you want to edit. And from the interactive rebase, just edit the commit. Makes sense!

ezyang commented 1 week ago

The important thing is ghstack modifies your commit messages after the first submit and you need to make sure you preserve the ghstack metadata!