首页 文章

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

提问于
浏览
3

我有一个bitbucket repo,它使用bitbucket-pipelines来部署到azure上的本地存储库(对于我们的开发服务器) . 我正在研究管道在部署到azure之前将使用的构建步骤 . 我的构建步骤现在唯一能做的就是将构建的文件输出到给定的目录中,该目录是gitignored . 然后强制添加gitignored构建文件夹 . 然后它修改了触发管道的提交,最后强制将提交推送到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

我的问题是:

Am I going to break anything with this git workflow? And are there any suggestions that you have?

我想只有我的管道脚本会推送到azure的本地仓库所以可以修改提交,否则如果其他人推动它可能是一个坏主意 . 这是我应该关注的吗?我想保留原始提交消息,因为azure将其显示在先前部署的列表中 . 如果它们都具有与其bitbucket提交相关的部署名称,那么返回某个部署会更加简单 .

我也想知道这是否可以使用 git push --force ,因为我听说 --force 标志被认为是危险的 . 由于我将构建文件提交给每个部署的git,因此我将提交一个提交文件,其中包含所有构建文件的repo . 我的想法是使用 --force 会忘记最后的迷失提交,只是让bitbucket-pipelines构建它的方式 . 我不确定我对 --force push 的解释是否正确 .

1 回答

相关问题