git-log--graph icon indicating copy to clipboard operation
git-log--graph copied to clipboard

Feature request: add option to fixup selected commit

Open christian-steinmeyer opened this issue 1 year ago • 3 comments

I'd like to be able to right-click a commit in the graph view and be able to create a fixup commit for that commit based on the currently staged changes.

christian-steinmeyer avatar May 23 '24 13:05 christian-steinmeyer

Hi, why not use VSCode's "commit amend" feature? Is it because you want to modify older commits?

I'm unsure on how to do that. GitLG internally just uses shell-commands that are valid on both Windows and Unix systems. Do you have any idea what the command would look like? Sounds like history rewriting stuff. There are two similar commands in place already. This one is for editing the commit message:

git diff-index --quiet HEAD && git merge-base --is-ancestor "{COMMIT_HASH}" HEAD && git commit --allow-empty --only -m "amend! {COMMIT_HASH}\n\n{NEW_COMMIT_MESSAGE}" && git -c sequence.editor=: rebase -i --autosquash "{COMMIT_HASH}^"

But apart from that, is fixuping the staged changes into an existing commit an action common enough to warrant a place in the default commit actions (which you can augment yourself)?

Also the difference between squash and fixup in this context seems to only be regarding the commit message (??). For message editing, there's already said other command so I wouldn't worry about that, we're in rare use case territory already anyway.

So yeah I guess we can do this but I definitely need some sample commands and guidance here.

phil294 avatar Nov 29 '24 21:11 phil294

Thanks for the response! Exactly, it is meant to "amend" an older commit while maintaining the original commit message (meant for e.g. typos, small mistakes etc.). It would be autosquash-able for easy rebasing, but in my case, I use it for the following workflow: I work on my own on a feature branch and create a merge request. Then someone reviews the MR. I address the requested changes either in new commits (if I add something new) or in fixup commits (if I made mistakes). I have It re-reviewed with nice UX for the reviewer and once everyone is happy, I simply rebase with autosquash enabled and voila, I have a nice branch that can be merged.

A command might look like git commit --fixup [SOME_COMMIT_SHA].

Admittedly, I'm afraid that fixup commits for many are an advanced topic (but in my personal opinion, they shouldn't! and having nice integration tools like this might help in that regard). I know that I would use it for sure! :)

christian-steinmeyer avatar Nov 29 '24 22:11 christian-steinmeyer

it is possible with custom actions

part of my config:

"git-log--graph.actions.commit": [
	{
		"title": "Fixup into this",
		"icon": "wand",
		"description": "Fixup current staged changes into this commit",
		"args": "commit --fixup=\"$1\"",
		"params": [{ "value": "{COMMIT_HASH}", "multiline": false, "placeholder": "commit hash", "readonly": false }],
		"immediate": false,
	},
	{
		"title": "Autosquash up to this",
		"icon": "fold",
		"description": "git rebase -i --autosquash $COMMIT",
		"args": "-c sequence.editor=: rebase -i --autosquash \"$1\"",
		"params": [{ "value": "{COMMIT_HASH}", "multiline": false, "placeholder": "Branch name", "readonly": false }],
		"immediate": false,
		"ignore_errors": false
	}
],

strayge avatar Aug 17 '25 15:08 strayge