Git混乱的命令来进行部署

  • 本文关键字:部署 命令 混乱 Git git
  • 更新时间 :
  • 英文 :


我正在做一个大项目,它有两个"主";git分支:masterdevelop。第一个(master(是生产分支,第二个(develop(是暂存分支。

前几天我一直在开发,今天我必须进行部署。一些同事告诉我这样做的步骤:

git fecth
git checkout develop
git pull origin develop
git checkout -b release/1.2.0
git tag v1.2.0
git push origin release/1.2.0
git push --tags
create a merge PR from release/1.2.0 to master
create a release for the new version specifying `master` as branch target and the changelog

这是我第一次需要做这样的事情,我不确定我是否完全理解。

我试着解释我所理解的:

git fecth # fetch all the remote changes
git checkout develop # I move to develop branch
git pull origin develop # fetch and merge develop changes in master branch (?)
git checkout -b release/1.2.0 # create the new branch release/1.2.0 and move inside it
git tag v1.2.0 # attach a tag to that branch (or commit?)
git push origin release/1.2.0 # push to master the new branch
git push --tags # push to master all the tags
create a merge PR from release/1.2.0 to master
create a release for the new version specifying `master` as branch target and the changelog

我很困惑。我想我不明白git pull origin develop的作用。。

您并没有真正感到困惑。你正确地描述了命令的作用。唯一错误的是你提到了主分支,从未在这里发挥过的作用。第三个命令只是从远程开发更新本地开发。类似地,推送不会推到master。它们使用命令中指定的分支名称推送到原点。

此外,命令本身有时也很愚蠢。说是荒谬的

git fetch
git checkout develop
git pull origin develop

第一个和第三个命令连续两次进行不必要的联网。更好的咒语是

git fetch
git checkout develop
git merge origin/develop

一般来说,在最后一行应该可以简单地说git merge,但没有特别的必要这样做

git pull origin develop应该用推送到同一分支上的其他提交来更新本地开发分支。

我建议先设置:

git config pull.rebase true
git config rebase.autoStash true

这样,您就可以origin/develop之上重新构建本地开发提交(尚未推送(的基础,而不是将origin/develop合并到develop:历史变得更加线性和清晰。

此外,我更喜欢git tag -m "v1.2.0" v1.2.0git tag -a v1.2.0,以便创建一个完整的注释标签,而不是一个轻量级标签(书签(:您可以向所述标签添加更多信息(授权、日期、相关消息(

最新更新