当特定用户选择旧提交时

当特定用户选择旧提交时

本文介绍了当特定用户选择旧提交时,Git推送新分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了触发一些自动化,我需要按照特定格式将具有分支名称的特定用户推送到gitlab存储库.为了参考起见,我们将该用户称为Joe Programmer <[email protected]>,并将分支名称称为example-branch.

In order to trigger some automation, I need to push to a gitlab repo as a specific user with a branch name following some specific formatting. For the sake of reference, let's call that user Joe Programmer <[email protected]> and the branch name example-branch.

我想抓取一个存在的提交并推送到gitlab,所以我更改了用户

There's a pre-existing commit that I want to grab and push to gitlab, so I change my user

git config --local user.name "Joe Programmer"
git config --local user.email "[email protected]"

删除分支(如果存在),并将该删除也推送到存储库中

delete the branch, if it exists, and push that delete to the repo as well

git push origin --delete refs/heads/example-branch
git branch -D example-branch

从我的已知有效提交中结帐

checkout from my known-good commit

git checkout good_commit

并从中分支

git checkout -b example-branch good_commit

然后我提交一个空的更改集并推送到原点.

then I commit with an empty change set and push to origin.

git commit -m "triggering automation" --allow-empty
git push origin example-branch

但是,当我查看Gitlab时,我发现它不仅是我的空提交(如Joe Programmer),而且是我在上面称为good_commit的上一个提交,归因于进行该提交的实际人员.

However when I look on Gitlab, I see that it's picked up not only my empty commit (as Joe Programmer) but also the previous commit I've called good_commit above, attributed to the actual person whose made that commit.

我如何最轻松地省略good_commit,所以唯一推到远程的是我作为Joe Programmer的提交?

How do I most-easily omit good_commit, so the only thing that pushes to remote is my commit as Joe Programmer?

推荐答案

一个选择(但可能并不完美)是修改最后一次提交.

One option, but probably not perfect, is to amend the last commit.

因此,您将执行以下操作:

So instead of an empty commit, you will do:

git commit  --amend --no-edit --author "Joe Programmer <[email protected]>"
git push origin example-branch

据我了解,您需要更改作者,因此还添加了--author

As far as I understood, you need a change of the author, so also added the --author

因此,缺点是每个分支具有相同内容(但散列不同)的重复提交,但它可能比那些空的触发自动化"提交要好.

So the downside is the duplicate commits with the same content (but different hash) per branch, but maybe it's better than those empty "triggering automation" commits.

这篇关于当特定用户选择旧提交时,Git推送新分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 02:40