Is there a way to squash a number of commits non
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?
确保你的工作树是干净的,然后
git reset --soft HEAD~3
git commit -m'new commit message'
I personally like wilhelmtell's solution:
git reset --soft HEAD~3
git commit -m 'new commit message'
However, I made an alias with some error checking so that you can do this:
git squash 3 'my commit message'
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)
#!/bin/bash
#
#get number of commits to squash
squashCount=$1
#get the commit message
shift
commitMsg=$@
#regular expression to verify that squash number is an integer
regex='^[0-9]+$'
echo "---------------------------------"
echo "Will squash $squashCount commits"
echo "Commit message will be '$commitMsg'"
echo "...validating input"
if ! [[ $squashCount =~ $regex ]]
then
echo "Squash count must be an integer."
elif [ -z "$commitMsg" ]
then
echo "Invalid commit message. Make sure string is not empty"
else
echo "...input looks good"
echo "...proceeding to squash"
git reset --soft HEAD~$squashCount
git commit -m "$commitMsg"
echo "...done"
fi
echo
exit 0
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 ):
#!/bin/sh
echo '-----------------------'
echo 'adding git aliases....'
echo '-----------------------'
echo
git config --global alias.squash "!bash -c 'bash <path to scripts directory>/squash.sh $1 $2' -"
#add your other git aliases setup here
#and here
#etc.
echo '------------------------------------'
echo 'here is your global gitconfig file:'
echo '------------------------------------'
more ~/.gitconfig
echo
echo
echo '----------------'
echo 'end of script...'
echo '----------------'
I used:
EDITOR="sed -i '2,/^$/s/^pickb/s/'" git rebase -i <ref>
Worked quite fine. Just don't try to have a commit log with a line that starts with "pick" :)
链接地址: http://www.djcxy.com/p/4748.html上一篇: 安装咕噜声
下一篇: 有没有办法压缩一些非提交的提交