繁体   English   中英

如何丢弃分支并从 master 带来更改

[英]how to discard a branch and bring the changes from master

我们当前的工作流程是这样的,每周一早上,我们想要丢弃所有合并到temp分支的提交,并将其镜像到最新版本的master分支。

但是,在整个一周内,不同的开发人员都会向 temp 分支提交提交,这些提交将被推送到 Gitlab。 我们想完全重置temp分支并将其带回master分支。

有多种方法可以实现这一点。 这里有两个相当直接的方法:(注意这些假设你的远程名称是“origin”):

git fetch                           # make sure your remote copy of master is updated
git checkout temp                   # checkout the temp branch if not already
git reset --hard origin/master      # reset temp to remote master
git push --force                    # push out the new temp branch to origin/temp

如果您愿意,可以将中间的两个命令合并为一个:

git fetch                           # make sure your remote copy of master is updated
git checkout -B temp origin/master  # checkout/create temp and reset to origin/master
git push --force                    # push out the new temp branch to origin/temp

旁注:当强制推送时,我几乎总是推荐使用git push --force-with-lease这样你就不会意外地删除你不知道的遥控器上的提交。 但是,我认为这是您实际上确实想要使用git push --force的罕见情况之一,因为听起来您无论如何都想重置temp分支; 即使有人在几分钟前向该分支推送了新的提交。

另一个旁注: Git 存储库本身使用称为Gitworkflows的分支策略,与您的策略一样,它有一个用于集成测试的一次性分支,并且会定期重置。 Git 维护人员将该分支称为next ,它代表“下一个”版本的候选功能。 (甚至还有一个名为pu的二级一次性分支,用于“提议的更新”。)只是认为您有兴趣知道您正在使用(可以说)经过验证的真实策略,至少关于您的temp分支。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM