I don't know exactly how to describe it in Git terms but what I do is:
Then git rebase -i HEAD~2
:
pick 34ea25a Add a search box f 9c4b283 fix
Save the file
But I would like to automate that, so how can I use git rebase without having to open an editor?
First of all, if you know that you are going to squash your next commit when doing it, you can just use git commit --amend
instead. Here's example workflow:
$ git commit -am "Add a search box"
$ vim file1.c # fix something
$ git commit --amend file1.c
Git interactive mode, as the name suggest, is designed for interactive use. You can, however, do this using GIT_SEQUENCE_EDITOR
environment variable or sequence.editor
config option. Both works the same - you can set them to some script that will get a standard interactive rebase file as an input. It's output will be used for actual rebase. You can see some suggestion on how to use it in this question .
My first solution is a simple one and works only if you have a clean branch, ie no untracked files, and only for the latest commit.
Add a shell script to a folder in your PATH
like ~/bin
and name it git-reword
-- make it executable.
#!/bin/bash
if [ -z "$1" ]; then
echo "Message missing"
exit 0
fi
git reset --soft HEAD^1
git commit -am "$1"
In your repo you can now type
$ git reword "new message"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.