cz-cli
                                
                                 cz-cli copied to clipboard
                                
                                    cz-cli copied to clipboard
                            
                            
                            
                        Support for amend (`--amend`)
When running git cz --amend I do not get the commitizen prompt, but instead the normal git way of editing message.
It would be awesome if it would show me the commitizen prompt again, especially since I most often use it when I forgot to run git cz.
Hi @LinusU. Thanks for the question.
This was asked in #12 but I'd like to hear more about what your use case / workflow is? Basically, this flag (--amend) is a built in git (not commitizen) command. Commitizen doesn't override this because if we did, and you had a spelling error in your commit message, you would not be able to edit it easily. We could add a new flag like --amend-over which more accurately describes that we're going to amend the same commit by overwriting the message with a new commitizen message.
Does this sound like what you want?
We could add a new flag like
--amend-overwhich more accurately describes that we're going to amend the same commit by overwriting the message with a new commitizen message.
That sounds very good 👍
Maybe even better would be if it could parse back to already written message to the answers, and suggest those as the default, but that would require updating all commitizen modules...
+1 for this option
A use case I just came trough, I made a rebase interactive and I want to amend my awful temporary commit message with git cz.
Same here. I'm not yet sure how to handle work in progress using commitizen. Usually, I would just dump my stuff into one (or multiple) and clean up later. But this clean up doesn't seem easy with commitizen (or at least I didn't find an easy way to do this yet, without creating a new branch and applying patches).
@jimthedev re: workflow
I think @inyono and @Calyhre hit the nail on the head. A common workflow for me is:
$ git commit -m 'trash'
$ git commit -m 'wip'
$ git commit -m 'not working'
$ git commit -m 'almost'
$ git commit -m 'finished, looks good'
$ git rebase -i master
# -----------
# squash everything down to one commit and abandon all the junk messages.
# but i want this first commit to be a commitizen message now...
p 'trash'  
f 'wip'
f 'not working'
f 'almost'
f 'finished, looks good'
#-------------
# rebase finishes, try to git cz
$ git cz # gonna do a nice message and rebase backwards to keep it
...
      throw new Error('No files added to staging! Did you forget to run git add?');
      ^
Error: No files added to staging! Did you forget to run git add?
...
$ git cz --amend # the problem as described by @LinusU. doesn't give me a commitizen prompt.
The existing git cz way of doing this would probably be to always git cz your last commit, but I often am not sure which commit will be the last one until after I've committed the work and had a look around. It just feels like you have to be really forward thinking to make this work naturally.
Personally, I think git cz --amend-over is a great solution, as long as its well-documented.
One workaround (that would also be useful for other use cases) would be to be able to run git cz and only get the output commit message (kind of a dry-run).
You'd be able to split a terminal in Vim (:vsplit | terminal), run git cz --dry-run in it, get the message, and paste it in your commit message directly.
You could also think of a Vim plugin that'd do it without any copy-paste. (But it'd solve the issue only for Vim users 😉 )
Any way to do that already? That would do the trick for me.
It's a very useful feature and taking into consideration that this issue is opened since 2016 there is no plan to create this new feature.
I found the following workaround:
- If you have many commits and want to join all of them in only one commit run git rebase -i [SHA1]where SHA1 is the hash of the commit before the commit you want to start to change. Your text editor will be opened with the list of commits then keep the first one with the pick instruction, and change all other to squash. When you save and close the file you will be guided to create a commit message with commitizen
- If you just made a commit and want to change the message run git reset --soft HEAD^to undo the latest commit and commit it again with the new message.
@educostadev I used to use cz via .git/hooks/prepare-commit hook but then I figured a much better way to do that: by using global git config to alias git cz like this:
# global git config
...
[alias]
     ...
     cz = "!npx git-cz"
This automatically calls git-cz via bash saving you from hitting ctrl+c  every time you run git commit --amend --no-edit etc.
Maybe even better would be if it could parse back to already written message to the answers, and suggest those as the default, [...] https://github.com/commitizen/cz-cli/issues/182#issuecomment-218808078
@LinusU That would make a lot of sense. If parsing fails, fallback to amending the commit manually. Maybe only the fields where one has to select from a restricted list are useful. And maybe the ones that are currently empty. And maybe the scope. The rest can be edited by hand. For instance I would be much more comfortable editing the description or deleting entire paragraphs in my editor.