可以将git配置为防止已发布的提交重新绑定? [英] Can git be configured to prevent rebase of already published commits?
问题描述
我想用 git pull --rebase
代替合并,但是这种方法可能会意外地重新绑定已经推送到另一个远程的提交。
$
有没有办法配置git,因此如果某些提交将会被拒绝,那么它会拒绝rebase rebased已被推送到其他远程?
试试这个命令:
git rebase --onto< remote> /< branch-name> $(git rev-list HEAD \
--not --exclude = $(git rev-parse --symbolic-full-name HEAD)\
--glob = refs / * - reverse | head -1)〜
这将仅在当前本地分支上进行提交。
如果您想将本地更改包含到尚未推送的其他分支,请更改 - glob = refs / *
表达式为 - 远程
。请注意,尽管您未来可能会推送这些本地分支机构,请谨慎使用。
澄清:
当然,因为您没有使用 git pull
,您需要在重新绑定之前执行 git fetch
。 (我恰好喜欢 git fetch
+ git rebase
或 git merge
,这样我就可以控制我重新绑定或合并的内容。)
I want to use the git pull --rebase
instead of merge but with this approach one can accidentally rebase commits that were already pushed to another remote.
In this case the merge on pull is mandatory.
Is there a way to configure git so it rejects the rebase if some of the commits that are going to be rebased was already pushed to other remote?
Try this command:
git rebase --onto <remote>/<branch-name> $(git rev-list HEAD \
--not --exclude=$(git rev-parse --symbolic-full-name HEAD) \
--glob=refs/* --reverse | head -1)~
This will rebase only commits that were done on the current local branch.
If you want to include local changes to other branches that were not pushed yet change the --glob=refs/*
expression to --remotes
. Please be aware, though that you may push these local branches in the future, so use with caution.
Clarification:
Of course, since you are not using git pull
, you will need to execute a git fetch
prior to rebasing. (I happen to prefer git fetch
+ git rebase
or git merge
, so that I can be in control of what I am rebasing onto or merging.)
这篇关于可以将git配置为防止已发布的提交重新绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!