如果提交是在本地完成的,请附加gerrit补丁集

时间:2017-03-23 04:34:10

标签: git merge version-control gerrit github-codereviews

我遇到的问题是:

我有一个git存储库我通过Pycharm的git插件在本地提交(不确定它的那部分是否相关)。我将这些更改推送到gitlab存储库。

现在,我必须进行代码审查。有人给我发了一个带有.gitreview文件的git存储库。他们告诉我克隆回购,复制/粘贴我的本地文件,然后按照以下步骤操作:

git clone http://repo-address/wow.git
cd wow
git review -s
git checkout -b fix_something

# ソース
tox -e py27 -e pep8 # for testing
git add # the files
gitt commit -m "コメント"
git review

我这样做了,我可以看到我的文件上传到gerrit。一些代码审查是在我的文件上完成的,每当我想上传修订或更改时,我都必须执行以下操作:

git review -d "the ID of the patch set you want to edit"

# Edit the source
tox -e py27 -e pep8 # Test command
git add files you want
git commit --amend
git review 

我非常确定我至少做过一次,但这就是事情变得有点模糊(因此我需要帮助的原因)。我确实编辑了一个补丁集并且至少修改了一次(我可以在gerrit上看到它,当我git diff它与之前的提交相比,那里有更改)。

然而,在这里我试图再次这样做并且它不能正常工作,可能是因为我不断对本地存储库进行更改而不是我克隆的存储库中包含.gitreview文件的存储库。我一直试图做的事情(可能是错误的)

  1. 更改本地回购
  2. 将本地存储库中的所有文件复制到包含.gitreview文件的存储库中
  3. 使用git review-d
  4. 执行上述步骤

    发生的事情是:

    error: unable to unlink old 'repo/__init__.py': Permission denied
    ...
    

    几乎每个文件。我认为这是因为复制我的本地东西并且只是硬覆盖一切都很糟糕。一位同事告诉我引用它(它在日语中抱歉:http://qiita.com/uasi/items/77d41698630fef012f82),这基本上是如何将两个存储库合并或合并为一个存储库的指南(同时保留提交历史记录)。我这样做了:

    cd ~/gerrit-repo
    git remote add hotfix ~/local-repo  # i assum the "hotfix" is just a name reference so i may have messed up here too
    git fetch hotfix
    git merge hotfix/master
    

    "工作"因为它复制并合并了所有内容,我所要做的就是解决.gitignore文件中的冲突。我现在可以做git审查,一切都应该没问题。问题在于,当我进行gitreview时,发生了以下情况:

    You are about to submit multiple commits. This is expected if you are
    submitting a commit that is dependent on one or more in-review
    commits. Otherwise you should consider squashing your changes into one
    commit before submitting.
    
    The outstanding commits are:
    
    0994069 (HEAD -> review/me/intit-test) Newest patch merge preparation (hopefully I didn't mess everything up)
    b49d7b4 checking whether the patch set stuff actually worked。
    8b3685b (hotfix-patch/master) patch-13-prep
    afdd1ca minor edits to log config
    5425ac7 reorganization re: patch set 12 code-review-1
    de57a63 reorganization re: patch set 12 code-review-1
    30133bf appended yuck func to xyz file
    f7760b9 init xyz file
    e48aa60 added log folder to ignore
    cdbbdf5 init setup.py
    76d0e9d created folders for the different configs needed for different servers. I don't know if these should all be accessible from one directory though.
    1599648 added command list for the checks
    ...
    

    我注意到自我最初提交以来的每一次提交都在那里。这是一个问题,因为我只想附加自上次git review / patch-set以来发生的本地目录的提交。无论如何,不​​管怎样,继续:

    remote: Resolving deltas: 100% (414/414)          
    remote: Processing changes: refs: 1, done            
    remote:
    remote: ERROR:  In commit 28064f...  # (this actually is the first commit in my local repo)      
    remote: ERROR:  committer email address aaa@google.com        
    remote: ERROR:  does not match your user account.        
    remote: ERROR:        
    remote: ERROR:  The following addresses are currently registered:        
    remote: ERROR:    bbb@google.com        
    remote: ERROR:        
    remote: ERROR:  To register an email address, please visit:        
    remote: ERROR:  http://gerrit-link/#/settings/contact        
    remote:
    remote:
    To ssh://gerrit-link:port/repo/project.git
     ! [remote rejected] HEAD -> refs/publish/master/intit-test (invalid     committer)
    error: failed to push some refs
    

    这对我来说很有意义但是不可取,因为本地提交是从我的本地机器完成的(而且相关的冲突提交实际上是我对repo的第一次提交)。我不确定是否必须解决初始提交时的电子邮件差异,然后才能查看,或者是否必须修复提交历史记录。我错误地认为自从上一个补丁集以来我只想要提交?如果是这样,我怎么只在gerrit补丁集中提交后附加提交?

    简而言之,我可以说我有一个我推销并正在管理的回购。我想将所有这些文件复制到不同标题下的另一个仓库/你有什么。我这样做,现在它是最新的。所以我想继续只使用这个新的回购。但是我不小心意外地继续在当地工作。如何将我的本地提交附加到新的提交?

2 个答案:

答案 0 :(得分:1)

  

简而言之,我可以说我有一个我推销并正在管理的回购。我想将所有这些文件复制到不同标题下的另一个仓库/你有什么。我这样做,现在它是最新的。所以我想继续只使用这个新的回购。但是我不小心意外地继续在当地工作。如何将我的本地提交附加到新的提交?

在新的本地仓库中,您添加了一个引用您的旧仓库的远程数据库,从中获取,并挑选您需要的提交:

cd /path/to/new/local/clone
git remote add oldrepo /url/old/repo
git fetch oldrepo

执行git branch -r查看oldrepo/xxx分支的位置,并git log oldrepo/xxx查看提交you need to git cherry-pick

答案 1 :(得分:1)

您也可以使用这种方式将提交从旧仓库转移到新仓库:

# In the new repo
git remote add old <path for the ole repo> -f
# find the commit id you want to move
git checkout -b temp <the commit id you want to move>
git checkout -
git merge temp
# solve the conflict if has and commit changes
git branch -D temp 
相关问题