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

标签 git azure build continuous-integration bitbucket-pipelines

我有一个 bitbucket 存储库,它使用 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

我的问题是:

我会破坏这个 git 工作流程中的任何东西吗?您有什么建议吗?

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

我还想知道现在是否适合使用 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”中建议的是将您的工件(构建文件夹中的二进制文件)发布到artifact repository .

不一定是 Nexus:请参阅“Build and Deploy your Java app to an Azure web app ”,它使用 FTP(取自 Azure portail 上的 Azure Web 应用程序 Gist 页面)。

关于git - 我应该在构建步骤中使用 `git push --force`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44535558/

相关文章:

python - 使用gitpython时如何设置git用户名和密码?

git - 应用使用 --all 创建的 git stash

.net - 从 A->Z 构建程序

regex - 带有 perl 正则表达式的 git 日志

git - 将存储库克隆到 GitHub

java - 如何从用 Java 编写的 Azure Function App 连接到 PostgreSQL?

ios - Microsoft Graph API 问题 iOS : Unable to Complete Request Validation Error

azure - 如何在 Azure 资源组模板中检索 Application Insights 实例的检测 key ?

android - 使用 SDK 安装 android NDK 后是否还需要手动安装 android NDK

java - ClassCastException : ApiVersionImpl cannot be cast to java. lang.Integer