If you want to move the HEAD
to the parent of the current HEAD
, that\'s easy:
git reset --hard HEAD^
But is there
The above method using git rev-list --all
considers all available commits, which can be a lot and is often not necessary. If the interesting child commits are reachable from some branch, the number of commits that a script interested in child commits needs to process can be reduced:
branches=$(git branch --contains $commit| grep -v '[*] ('| sed -e 's+^..++')
will determine the set of branches that $commit is an ancestor of.
With a modern git, at least version 2.21+, this should do the same without the need for sed
(untested):
branches=$(git branch --format='%(refname:short)' --contains $commit| grep -v '[*] (')
Using this set, git rev-list --parents ^$commit $branches
should yield exactly the set of all parent-child relationships between $commit and all branch heads that it is an ancestor of.