5

While working on my feature branches, I constantly re-order and squash them with git rebase -i to keep a cleaner version of my history. Sometimes I work on several features that depend on each other (the rules in my team are to make PRs as small as possible, so one atomic chunk of a larger feature usually becomes a feature branch of its own). As a result of this workflow, I usually end up re-pointing branches manually after rebasing them. Is there a way to automatically move these pointers to where they should land?

So, for instance, in this graph:

5bab4818e (HEAD -> cell-toggle-comp) Added cell-toggle component
d55cab881 (toggle-comp) Toggle: Added honey traceability comment
4240f0ac3 Made Toggle a named export and replaced references to obsolete <ui> alias
90a0b2452 Refactored Switch instances to toggle
e15c758a0 Updated Switch component to latest specs (and renamed things to match design lingo)
d53090e93 (fix-switch-reference) Fixed Switch reference that was being imported from React Native instead of src/components
4a214cb72 (cell-text-selection-comp) Added CellTextSelection ui component
cef3b5716 (origin/master, origin/HEAD, master) Merge pull request #1630 from repo

Let's say that I want to swap commits e15c758a0 and d53090e93, but I want the fix-switch-reference branch to move along with its commit. Is there a way to do that automatically? Or do I have to move the commits and then point the branch to the new hash by hand?

sdeleon28
  • 329
  • 1
  • 11
  • What do you mean by swapping commits? Do you mean rebasing `d53090e93` on top of `e15c758a0`? – matb Jul 09 '18 at 18:44
  • He means swapping their order in history. – pishpish Jul 09 '18 at 18:47
  • @sdeleon28 how about `git rebase --onto e15c758a0 fix-switch-reference`? That should keep the branch pointing at the latest HEAD after rebasing. How were you exactly rebasing your commits before? – matb Jul 09 '18 at 18:53
  • @matb that will not keep `toggle-comp` for instance (since swapping those two commits means all subsequent commits will change SHAs) – sdeleon28 Jul 24 '18 at 14:30
  • Possible duplicate of: https://stackoverflow.com/questions/20834648/how-do-i-rebase-a-chain-of-local-git-branches, https://stackoverflow.com/questions/5600659/rebasing-a-branch-including-all-its-children, https://stackoverflow.com/questions/5628236/when-git-rebasing-two-branches-with-some-shared-history-is-there-an-easy-way-to, https://stackoverflow.com/questions/866218/how-to-rebase-many-branches-with-the-same-base-commit-at-once, https://stackoverflow.com/questions/42181045/modify-base-branch-and-rebase-all-children-at-once – Daniel McIntosh Jul 08 '22 at 18:30

0 Answers0