Git replace changes-替换已经提交的代码

Replace Changes

To add an additional patch set to a change, ensure Change-Idlines were created in the original commit messages, and just usegit push URL HEAD:refs/for/... as described above.Gerrit Code Review will automatically match the commits back totheir original changes by taking advantage of the Change-Id lines.

If Change-Id lines are not present in the commit messages, consideramending the message and copying the line from the change’s pageon the web, and then using git push as described above.

If Change-Id lines are not available, then the user must use themanual mapping technique described below.

For more about Change-Ids, see Change-Id Lines.

Manual Replacement Mapping
Deprecation Warning

The remainder of this section describes a manual method of replacingchanges by matching each commit name to an existing change number.End-users should instead prefer to use Change-Id lines in theircommit messages, as the process is then fully automated by Gerritduring normal uploads.

See above for the preferred technique of replacing changes.See above for the preferred technique of replacing changes.

To add an additional patch set to a change, replacing it with anupdated version of the same logical modification, send the newcommit to the change’s ref. For example, to add the commit whoseSHA-1 starts with c0ffee as a new patch set for change number1979, use the push refspec c0ffee:refs/changes/1979 as below:

git push ssh://sshusername@hostname:29418/projectname c0ffee:refs/changes/1979

This form can be combined together with refs/for/'branchname'(above) to simultaneously create new changes and replace changesduring one network transaction.

For example, consider the following sequence of events:

$ git commit -m A                    ; # create 3 commits
$ git commit -m B
$ git commit -m C
$ git push ... HEAD:refs/for/master  ; # upload for review
... A is 1500 ...
... B is 1501 ...
... C is 1502 ...
$ git rebase -i HEAD~3               ; # edit "A", insert D before B
                                     ; # now series is A'-D-B'-C'
$ git push ...
    HEAD:refs/for/master
    HEAD~3:refs/changes/1500
    HEAD~1:refs/changes/1501
    HEAD~0:refs/changes/1502         ; # upload replacements

At the final step during the push Gerrit will attach A' as a newpatch set on change 1500; B' as a new patch set on change 1501; C'as a new patch set on 1502; and D will be created as a new change.

Ensuring D is created as a new change requires passing the refspecHEAD:refs/for/branchname, otherwise Gerrit will ignore D andwon’t do anything with it. For this reason it is a good idea toalways include the create change refspec when uploading replacements.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值