当前位置:   article > 正文

Git replace changes-替换已经提交的代码_git 提交里的代码替换字符串

git 提交里的代码替换字符串

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.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/920746
推荐阅读
  

闽ICP备14008679号