I'm trying to squash a range of commits - HEAD to HEAD~3. Is there a quick way to do this, or do I need to use rebase --interactive?
相关问题
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
- Upload file > 25 MB on Github
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- git: retry if http request failed
Here is a one liner to squash the last 2 commits. In this example, the message of second last commit will be retained. You may change the message as you wish.
This command will be very useful if you create an alias for this command and use the alias instead.
You can get pretty close with
This assumes you're on master with a linear history. It's not quite a squash because it discards the intermediate commits. You'd need to amend the new HEAD to modify the commit message.
I personally like wilhelmtell's solution:
However, I made an alias with some error checking so that you can do this:
I recommend setting up aliases that actually run scripts so that it is easier to (a) code up your scripts and (b) do more complex work with error checking. Below is a script that does the work of squash and then below that is a script for setting up your git aliases.
Script for squashing (squash.sh)
Then to hook up that squash.sh script to a git alias, make another script for setting up your git aliases like so (create_aliases.command or create_aliases.sh):
I used:
Worked quite fine. Just don't try to have a commit log with a line that starts with "pick" :)
Use the following command to squash the last 4 commits within the last commit:
With the alias:
From https://github.com/brauliobo/gitconfig/blob/master/configs/.gitconfig
To add to the answer by wilhelmtell I find it convenient to soft reset to
HEAD~2
and then amending the commit ofHEAD~3
:This will merge all commits to the
HEAD~3
commit and use its commit message. Be sure to start from a clean working tree.