Ada*_*sen 24 git bash git-merge githooks git-branch
前段时间我要求我们的开发人员在推送之前使用rebase而不是merge.消除琐碎的合并使得更容易遵循提交图(即:gitk,git log).
有时人们仍然不小心做了琐碎的合并,然后推.有没有人有方便或有写一个阻止琐碎合并的服务器端钩子的技巧?
通过"琐碎的合并",我的意思是合并没有冲突.这是一个例子,这里是对git中一个简单合并的更好解释.
更新Wed Wed 10 01:26:41 UTC 2010:好评,全部!谢谢.
git pull --ff-only失败,请做git pull --rebase而不是git pull更新时间:11月11日星期二23:49:35 UTC:
更新Wed Dec 15 18:34:52 UTC 2010:
在尝试寻找解决方案时,我遇到了这段代码.它并不完全符合您的要求,但应该在if语句中添加额外的分支名称.
到目前为止,对我有用.它强制拉动--rebase为同一个分支,并允许与其他分支的常规合并通过.
所有学分都归原作者所有.
#!/bin/bash
#
# This git update hook will refuse unnecessary merge commits caused by pulling
# from being pushed to a shared repository. These commits make following the
# history of a project difficult and are always avoidable with rebasing.
#
# by Scott Kyle (appden)
# modified by Olivier Refalo (orefalo)
refname="$1"
oldrev="$2"
newrev="$3"
# if this is not run as a hook, you may have messed up
if [ -z "$GIT_DIR" -o -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
echo "Usage: GIT_DIR=<path> $0 <ref> <oldrev> <newrev>" >&2
exit 1
fi
# if the new revision is all 0's then it's a commit to delete a ref
zero="0000000000000000000000000000000000000000"
# also check if the new revision is not a commit or is not a fast forward
# detect branch deletion, branch creation... and more
if [ "${refname#refs/heads/}" = "master" ] || [ "$newrev" = "$zero" ] || [ "$oldrev" = "$zero" ] || [ $(git cat-file -t $newrev) != "co
mmit" ] || [ $(git merge-base $oldrev $newrev) != "$oldrev" ]; then
exit 0
fi
# loop through merges in the push only following first parents
for merge in $(git rev-list --first-parent --merges $oldrev..$newrev --); do
# lazily create the revision list of this branch prior to the push
[ -z "$revlist" ] && revlist=$(git rev-list $oldrev)
# check if the second parent of the merge is already in this branch
if grep -q $(git rev-parse $merge^2) <<< "$revlist"; then
cat >&2 <<-EOF
*** PUSH REJECTED ***
*** TRIVIAL merge detected on local branch ${refname#refs/heads/}
*** To fix: git rebase origin/${refname#refs/heads/}
***
*** Next time use: git pull --rebase
***
*** Permanent fix: git config [--global] branch.autosetuprebase always
*** Then for existing branches: git config branch.<name>.rebase true
EOF
exit 1
fi
done
echo -Info- Clean history successfully preserved!
exit 0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5196 次 |
| 最近记录: |