gitmergeversion-controlgerritgithub-codereviews

Append gerrit patch-set if commits were done locally


The issue I'm having is this:

I have a git repository I was committing to locally via Pycharm's git plugin (not sure if that part of it is relevant). I pushed those changes to a gitlab repository.

Now, I have to do codereview. Someone sends me a git repository with a .gitreview file in it. They told me to clone the repo, copy/paste my local files in, and follow the following steps:

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

I did this, and I could see my files uploaded to gerrit. Some code review was done on my files and whenever I wanted to upload revisions or changes I would have to do the following flow:

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 

Which I am pretty sure I did properly at least once, but this is where things get a little murky (hence why I need help). I definitely did edit a patch set and properly amend it at least once(I can see it on gerrit and when I git diff it vs. a previous commit the changes are there).

However, here I am trying to do it again and it isn't working properly, possibly because I kept making the changes to the local repository instead of the repository I cloned that had the .gitreview file in it. What I've been trying to do do (and is probably wrong)

  1. change the local repo
  2. copy all of the files from the local repo into the repo with the .gitreview file in it
  3. execute the above steps with git review-d

And what's been happening is:

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

For just about every file. I assume this is because copying my local stuff and just hard overwriting everything was bad. A colleague told me to reference this (it's in japanese sorry: http://qiita.com/uasi/items/77d41698630fef012f82) which is basically a guide on how to merge or consolidate two repositories into one (preserving the commit history as well). I followed this by doing:

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

which "worked" in that it copied and merged everything, and all I had to do was resolve a conflict in the .gitignore file. I can now just do git review and everything should be fine. The issue is that when I did gitreview the following happened:

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
...

I notice that every single commit since my initial commit was there. Which is a problem, since I only want to append the commits from my local directory that happened since the last git review / patch-set. Anyway, continued regardless and then:

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

Which makes sense to me but is undesirable, since the local commits were done from my local machine (and the conflicting commit in question is actually my first commit for the repo). I'm not sure if I have to resolve the e-mail difference on the initial commit and then would be able to review, or whether I have to fix the commit history as well. Am I wrong in thinking that I should want commits only since the last patch set? If so, how do I only append the commits since the commit in the gerrit patch-set?

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?


Solution

  • You can also use this way to move the commit from old repo to new repo:

    # 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