user187676
user187676

Reputation:

rebase: Reset First Commit in Interactive Rebase

Usually when editing a commit in interactive rebase I do the following when it stops on an edit line:

git reset --soft HEAD^

to reset the commits' files. However, when the rebase was started from --root with

git rebase -i --root

and we are editing the very first commit, this can obviously not be done because HEAD^ doesn't exist.

How do I perform the reset for the very first commit within an interactive rebase?

Upvotes: 0

Views: 92

Answers (1)

LeGEC
LeGEC

Reputation: 51860

In that case : it is easier to use commit --amend after staging the edited content.


I don't see a straightforward way to emulate a "git reset on emptyness" with a detached HEAD :
git accpets to have ref: refs/non_existing_ref int its HEAD file, but refuses to have an empty HEAD file.

A hacky way would be :

# pseudo code, the following is not valid syntax in any language

if current HEAD has no parent :
    # create a phony ref :
    echo "ref: refs/hacky_reset_root_commit" > .git/HEAD
    # the index already holds the content of current commit
else :
    git reset --soft HEAD^

# proceed with your processing ...

git commit

if '.git/HEAD' content is 'ref: refs/hacky_reset_root_commit' :
    # switch back to detached HEAD mode :
    git checkout $(git rev-parse HEAD)
    # delete phony ref :
    git update-ref -d refs/hacky_reset_root_commit
else:
    # nothing more to do

Upvotes: 1

Related Questions