git&gerrit 使用过程中遇到的问题及解决方法

公司中使用git进行代码管理, 使用gerrit 来做code review及权限管理。

在使用的过程中, 遇到了不少问题, 现把它分享出来, 供大家参考。

push 失败

【现象】git push 出错, ! [remote rejected] master -> master (prohibited by Gerrit)

error: failed to push some refs to xxxx

【原因】通常是因为没有某个分支的push权限导致的,出现在不经过CodeReview直接push入库的情况下。

【解决】找project owner帮忙开通该分支的push权限,如果owner同意的话。若不同意, 那就说明你不能直接push入库, 必须经过 

CodeReview。

2.分支合并时,慎用git merge

【现象】开发者在 dev分支上做开发,有已入库的commit1/commit2/.../commitN, 当checkout 到master, 做merge dev操作的时候,这些dev分

支上的commits会自动迁入master分支(可能需要解决merge conflict)。但当对此次merge发起CodeReview的时候, 这些来自dev分

支的commits 不会出现在CR的列表中。

【原因】a commit was pushed directly to a branch (without going through code review) you cannot push this commit 

once again for code review。一个commit只要入库了, 那么就不能出现在CodeReview中了。

【解决】慎用git merge, 如果一定要用的话, 使用git merge --squash branchName,squash会将被合并分支上的commit压缩成

一个新的commit, 这样发CR的时候, 被合并分支上的commit的内容都会包含进来。

使用 rebase or cherry-pick

3.git fetch/git clone 失败

【现象】git clone 一个大的项目时失败,错误类似fatal: The remote end hung up unexpectedly | fatal: early EOF | fatal: index-pack failed

【原因】项目过大,受硬件限制(类似过载保护),clone过程中会中断

【解决】    先做一个浅:git clone --depth 1 <repo_URI>;将浅repo回复完全:git fetch --unshallow ;then do regular pull :git pull --all

4.gerrit web 端无法找到某个change

【现象】https://git.xxxxx.com/#/c/8645/ 出现Not Found, 而实际上查询后端数据库是能够找到这个change的 select * from changes 

where change_id=8645\G;git fetch 等操作亦可执行。

【解决】使用 gerrit set-reviewer/ review 命令对该change 进行设置reviewer, 做CR及submit/abandon 操作等。e.g. abandon the change :

先加reviewer

ssh -p 29418 user@git.xxxxx.com gerrit set-reviewers -a user_to_add86454

再abandon

ssh -p 29418 user@git.xxxxx.com gerrit review --abandon 769f636e, 此处的数字串是change 86454对应的commit id

5.用户的public key已经配置,但 clone操作是, 仍提示permission denied (publickey)。 

【现象】查看后台log, 发现log显示”AUTH FAILURE FROM 100.64.8.159 user-not-found” 

【解决】在web ui->settings->profile看下, username是否做了设置.

6.使用jenkins的gerrit-trigger后, 发现gerrit 日志中出现warning

【现象】WARN com.google.gerrit.server.change.PostReview : notify = null; assuming notify = NONE 

【解决】原因:持续集成中使用的 jenkins gerrit-trigger 在发表review comments的时候, 没有使用 --notify导致没有触发邮件通知的原因。

不是大问题。 Make sure that the 'gerrit review' command used by Jenkins to post reviews contains the '--notify' option [1].

If it is not set, by default, no email notification is triggered (as you can see from the warning the you posted above). 

The Gerrit Trigger plugin allows to configure the command to post reviews in its advanced settings.

7. gc VS repack

对某个project进行瘦身, 降低project的大小。实践发现,gc的效果更好。gc后大小大约为原来的1/3。

8. 找回已经删除的commit

git reflog 找到那个commitID, 或者可以通过 git log -g 获取更加详细的commit信息。reflog保存的是历次对于HEAD的修改

然后git reset --hard commitID直接回到那个commit

或者使用git cherry-pick commitID,将那个commit的内容拿到当前(可能需要解冲突),同时生成一个新的commit


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值