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

Append gerrit patch-set if commits were done locally

我遇到的问题是:

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

现在,我必须进行代码审查。有人向我发送了一个 git 存储库,其中包含一个 .git 审查文件。他们告诉我克隆存储库,copy/paste 我的本地文件,然后按照以下步骤操作:

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 将它与之前的提交进行比较时,更改就在那里)。

但是,我在这里尝试再次执行它,但它无法正常工作,可能是因为我一直在对本地存储库进行更改,而不是我克隆的具有 .gitreview 的存储库文件在里面。我一直在努力做的事情(可能是错的)

  1. 更改本地存储库
  2. 将本地存储库中的所有文件复制到包含 .git审查文件的存储库中
  3. 用gitreview-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

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

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 审查/补丁集以来发生的本地目录中的提交。无论如何,继续不管然后:

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

这对我来说有意义但不受欢迎,因为本地提交是从我的本地计算机完成的(并且有问题的冲突提交实际上是我对回购的第一次提交)。我不确定我是否必须解决初始提交时的电子邮件差异然后才能进行审查,或者我是否还必须修复提交历史记录。我认为我只需要自上次补丁集以来的提交是错误的吗?如果是这样,我如何仅在 gerrit 补丁集中追加自提交以来的提交?

简而言之,假设我有一个我推送并正在管理的回购协议。我想将所有这些文件复制到另一个 title/what 下的另一个仓库。我知道,现在它是最新的。所以我只想继续处理这个新的回购协议。但是我不小心继续在原来的本地工作。如何将我本地提交的提交附加到新提交?

In shorter words, lets say that I have a repo that I pushed to and am managing. I want to copy all of these files to another repo under a different title/what have you. I do, and now its up to date. So I want to continue working only on this new repo. But I accidentally kept working on the original local one by accident. How do I append the commits from my local one to the new one?

在你的新本地回购中,你添加一个远程引用你的旧回购,从中获取,然后挑选你需要的提交:

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.

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

# 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