我应该在我的构建步骤中使用 `git push --force`

Should I use `git push --force` in my build step

我有一个 bitbucket 存储库,它使用 bitbucket-pipelines 部署到 azure 上的本地存储库(用于我们的开发服务器)。我正在研究管道在部署到 Azure 之前将使用的构建步骤。我的构建步骤现在唯一做的就是将构建文件输出到给定的目录中,该目录被 git 忽略。然后强制添加 gitignored build 文件夹。然后修改触发管道的提交,最后强制将提交推送到 master。

所以我的文件看起来像这样

# bitbucket decided to make the repository shallow this line
# makes the repo unshallow so we can push later
- git fetch  https://<bitbucket-repo> --unshallow
# doing some setup so we can run the build scripts
- npm install
- npm install -g gulp
# just building files for now we can add tests in later
- npm run build:single
# forcing the build files to be included in the commit
# so that azure has access to the files.
- git add --force public/build/ 
# do some git configuration so it will let us commit
- git config --global user.email $GIT_USER_EMAIL
- git config --global user.name "$GIT_USER_NAME"
# add to the last commit so we can keep its message
# this is so we can see the last commit message that was
# done on azure without creating a new commit message
# this command edits the previous commit and should
# never be done when that commit has already been 
# pushed to your target branch and if your target branch is
# public.
- git commit --amend --no-edit
# the below line pushes to a branch on azure we setup as a local branch
- git push --force https://<azure-branch-repo> master

我的问题是:

我会破坏这个 git 工作流程吗?您有什么建议吗?

我认为只有我的管道脚本会推送到 Azure 的本地存储库 所以修改提交是可以的,否则如果其他人推动它可能是一个坏主意。这是我应该关心的事情吗?我想保留原始提交消息,因为 azure 在以前的部署列表中显示它。如果他们都有与他们的 bitbucket 提交相关的部署名称,那么返回到某个部署就容易多了。

我还想知道现在是否适合使用 git push --force,因为我听说 --force 标志被认为是危险的。由于我将每次部署的构建文件提交到 git,因此我将提交一个偏离包含所有构建文件的存储库的提交。我的想法是使用 --force 会忘记最后一次杂散提交,并按照 bitbucket-pipelines 构建它的方式拥有所有内容。我不确定我对 --force push 的解释是否正确。

you should note that this is for my development servers. It's set up to be automated so it's less hassle during development, but during deployment to production we copy files over manually

即便如此,Git 并非用于部署或存储可以生成的构建工件。
我在“Separate development and deployment git repositories" is to publish your artifacts (the binaries in the build folder) to an artifact repository.

中提出的建议

它不一定是 Nexus:请参阅“Build and Deploy your Java app to an Azure web app", which uses FTP (taken from the Azure web app essentials page on the Azure portail”。