phil294 / GitLG

A free, interactive Git UI for VSCode
MIT License
155 stars 15 forks source link

Ability to edit the commit message, at least when the change hasn't been pushed to the origin(s) #87

Open webJose opened 7 months ago

webJose commented 7 months ago

My ask is a very simple one: Based on the fact that I don't want to keep on learning the git CLI (or any CLI for that matter), I like graphical extensions like this one for source control.

One thing I was about to ask Git Graph to have (before I found out it was abandoned), was to be able to simply right-click a line in the graph and be able to select a "Edit commit message..." option that would do all the needful to change the commit message. It is my understanding that this is far simpler when the committed change hasn't been pushed to the origin, so I would like to have this for at least commits that haven't been pushed.

Many thanks for the time invested reading my request. Cheers!

phil294 commented 7 months ago

This is a good idea, will definitely add this. Common use case, way too unintuitively implemented in Git CLI (like most things).

This will then only affect the local commit. If it's pushed already, it will also work but require a follow-up pull I think (or push --force)

webJose commented 7 months ago

Thank you very much for the good news! I will impatiently await for the feature release. Yes, I'll be happy to have the option for local commits at the very least. You see, I, more often than I would like to admit, forget to add the ticket ID footer that is requested by my organization (conventional commits, footer). A graphical option to get the current message in a textbox, modify, click a Save button and be done is my ideal solution to this.

phil294 commented 7 months ago

You can already add this feature to the extension with this option:

    "git-log--graph.actions.commit": [{
        "title": "Edit message",
        "icon": "edit",
        "info": "Only works when your work tree is clean (no changed files). Use at your own risk.",
        // taken from here https://stackoverflow.com/q/76794264
        "args": "diff-index --quiet HEAD && _2=\"$2\" && git commit --allow-empty --only -m \"amend! $_2\n\n$1\" && git -c sequence.editor=: rebase -i --autosquash \"$_2^\"",
        "params": ["New commit message", "{COMMIT_HASH}"]
    }]

Works great for me. However, this probably only works on Linux/Mac, not Windows. And when you have unsaved changes, there is no warning but a unhelpful error popup comes up. And you can only specify single-line messages. And the commit message isn't pre-filled with the previous one.

All of these problems need fixes in the source, but for rudimentary renaming, it's fine :)

phil294 commented 7 months ago

forget to add the ticket ID

haha, yes, same, all the time :D

A graphical option to get the current message in a textbox, modify, click a Save button and be done is my ideal solution to this.

yes, I think that should be done with the setting I posted, or at least with how it will be after next release

phil294 commented 7 months ago

Implemented with version 0.1.15. Unfortunately, prefilling the message field with the existing commit message would be - once again - too complex, so for now to alter something, you have to copy paste the existing one. This extension's architecture is increasingly showing some shortcomings for adding more advanced features. Perhaps I'll have to rethink some concepts.

Anyway, this is quite an unusual feature for any Git client to have and rewriting history should usually be avoided, so having this feature in the first place is rather rare already.

phil294 commented 7 months ago

Editing works for any commit, regardless of how far back it is or if you have pushed or not. Needs to be on your currently checked out branch though.