git squash bash Пример скрипта для объединения коммитов -- squashCurrentBranchCommits()
Primary tabs
Пример скриптов для слияния, объединения коммитов:
# Black 0;30 Dark Gray 1;30
# Red 0;31 Light Red 1;31
# Green 0;32 Light Green 1;32
# Brown/Orange 0;33 Yellow 1;33
# Blue 0;34 Light Blue 1;34
# Purple 0;35 Light Purple 1;35
# Cyan 0;36 Light Cyan 1;36
# Light Gray 0;37 White 1;37
YELLOW='\033[1;33m'
CYAN='\033[0;35m'
NC='\033[0m'
function squashCurrentBranchCommits() {
# set -x
CURRENT_BRANCH="$(git symbolic-ref --short HEAD)"
echo -e "${YELLOW}!!! Squash commits ${NC} for ${CURRENT_BRANCH}"
echo -e "${YELLOW}Fetching master.....${NC}"
git fetch origin master
echo -e "${YELLOW}Fetching ${NC} current ${CURRENT_BRANCH}"
git fetch origin ${CURRENT_BRANCH}
echo -e "${YELLOW}Create master clone ${NC} master-new branch"
git checkout -B master-new origin/master
echo -e "${YELLOW}Merge ${NC} ${CURRENT_BRANCH} into master-new"
git merge --squash origin/${CURRENT_BRANCH}
git commit -m "${1:-Squash all previous commits}"
echo -e "${YELLOW}Push --force! ${NC} master-new into ${CURRENT_BRANCH} "
COMMAND="git push --force -u origin master-new:${CURRENT_BRANCH} ${2}"
echo -e "${YELLOW} By Command: [[ ${NC} ${COMMAND} ${YELLOW} ]] ${NC} "
bash -c "${COMMAND}"
#${COMMAND}
echo -e "${CYAN}Finished: Push --force ${NC} master-new into ${CURRENT_BRANCH} "
echo -e "${YELLOW}Returning to ${NC} to ${CURRENT_BRANCH} (by git reset --hard) "
git checkout ${CURRENT_BRANCH}
git fetch origin ${CURRENT_BRANCH}
git reset --hard origin/${CURRENT_BRANCH}
echo -e "${YELLOW}Ready!${NC} ${CYAN}Show git status ${NC}: "
git status
# set +x
}
-- здесь мы проводим объединение коммитов через merge
пример вызова:
squashCurrentBranchCommits "Add new funcitions"
Также вторым аргументом команды можно навесить флаги на стадию push-а ветки, например (копируем сразу обе строки):
squashCurrentBranchCommits "Add new funcitions" \ "--no-phplinter --message \"we need this\""
Эта функция входит в наш набор git-scripts
- Log in to post comments
- 409 reads