gerrit error

2016/07/17

Gerrit

1. git commit —amend之后,git push

 ! [remote rejected] HEAD -> refs/for/master (change http://gerrit/10993 closed)
 ! [remote rejected] HEAD -> refs/for/master (missing Change-Id in commit message footer)
  error: failed to push some refs to 'ssh://xxxxxxxxxxxx'

这是最笨的办法也最实用 git reset 最开始的commitId, 然后再去commit,push 或者 git cherry-pick commitId 将之前的提交记录同步

 ! [remote rejected] HEAD -> refs/for/feature_fit_v2 (change http://gerrit/19291 closed)
error: failed to push some refs to 'ssh://hehehe@gerrit:29418/project/demo'

因为19291这条change已经merge,到remote延迟导致reset feature_fit_v2,然后我git fetch,push后报错,有时是因为没有git fetch。

2. git status

On branch master
`Your branch and 'gerrit/master' have diverged,`
and have 1 and 1 different commit each, respectively.
  (use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean
git status
rebase in progress; onto 62ea959
You are currently rebasing branch 'master' on '62ea959'.
  (all conflicts fixed: run "git rebase --continue")

Not currently on any branch.
—— git status
HEAD detached at 97b7f6c
nothing to commit, working directory clean

终极解决:git reset --hard gerrit/master, 然后git commit, git push

3. error: src refspec HERD does not match any.

引起该错误的原因是,目录中没有文件,空目录是不能提交上去的

! [remote rejected] HEAD -> refs/for/master (internal error)

查看here

4. error: insufficient permission for adding an object to repository database ./objects

5.

git status
On branch master
Your branch is ahead of 'gerrit/master' by 2 commits.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean
   

使用git pull –rebase解决

使用git pull --rebase
remote: Counting objects: 37, done
remote: Finding sources: 100% (19/19)
remote: Total 19 (delta 11), reused 18 (delta 11)
Unpacking objects: 100% (19/19), done.
From ssh://xxx
6132a74..2655ed6  master     -> gerrit/master
   

解决成功是用的这里的内容

  1. Do a local rebase (git pull –rebase)
  2. Someone clicks “Rebase change” on Gerrit (which results in the same base tree, but different date and/or commiter name)
  3. Try to push to Gerrit
  4. 网页原文 Result: The commit is rejected (following commits, if there are any, are therefore rejected as well, although this happens silently).

6 Could not read from remote repository

git fetch
fatal: No remote repository specified.  Please, specify either a URL or a
remote name from which new revisions should be fetched.

git fetch gerrit/dev
fatal: 'gerrit/dev' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

以上错误是因为没有个远程分支绑定,可直接修改vi .git/config 把 dev分支应的远程改为 gerrit/dev

7 No user exists for uid 501, fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

ssh ip
id

重启终端就好了,终端导致的ssh重启。

一系列解决问题的网址

  1. http://www.jianshu.com/p/ae4857d2f868
  2. http://www.cnblogs.com/Security-Darren/p/4383838.html
  3. http://m.blog.csdn.net/article/details?id=46583217
  4. http://blog.csdn.net/csfreebird/article/details/7583363

Git

github 使用 —amend 时报错,然后需要重新pull

git add .
➜  project git:(master) ✗ git commit --amend
[master 1a5bace] format
 Date: Wed Nov 2 17:31:24 2016 +0800
 4 files changed, 11 insertions(+), 8 deletions(-)
➜  project git:(master) git push
To https://github.com/xxx/project.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/xxx/project.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

需要pull的时候

git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commit each, respectively.
  (use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean
➜  project git:(master) ✗ git reset --soft origin/master
➜  project git:(master) ✗ git status
On branch master
Your branch is up-to-date with 'origin/master'.

合并A分支的一部分到B分支

  1. commits,摘自

     git checkout B_branch
     git cherry-pick 9877111 //这个commit就被合并到B分支
    	
     一系列commit,使用rebase,如果合并的commit是 977633-9877111到B分支,需要基于A分支创建一个新的分支A1_branch,并指明A1_branch的最后一个commit:
     git checkout -b A1_branch 9877111
     git rebase --onto B_branch 977633^ (977633^指明commit的开始)
    
  2. file

     git checkout B_branch
     git checkout --patch B_branch a.txt//合并A分支的文件到B分支
     或者git checkout A_branch a.txt //将A分支的文件copy到B分支
    

文内导航