将非git项目转换为git项目并将其推送到gerrit repo

时间:2016-01-08 12:14:42

标签: git gerrit git-review

我试图了解git和gerrit几天,并且有一些错误,我找不到合适的解决方案。这是错误消息;

*asfaa@asadaf:~/test$ git review -R
Could not connect to gerrit.
Enter your gerrit username: remote0
Trying again with ssh://<username>@<ip>:29418/test
Creating a git remote called "gerrit" that maps to:
    ssh://<username>@<ip>:29418/test
This repository is now set up for use with git-review. You can set the
default username for future repositories with:
  git config --global --add gitreview.username "remote0"
Your change was committed before the commit hook was installed.
Amending the commit to add a gerrit change id.
remote: Processing changes: refs: 1, done    
To ssh://<username>@<ip>:29418/test
 ! [remote rejected] HEAD -> refs/publish/master (no common ancestry)
error: failed to push some refs to 'ssh://<username>@<ip>:29418/test'*

我在以下步骤后得到此错误;

  • 我使用命令&#34; ssh -p 29418 user @ localhost gerrit create-project project_name&#34;
  • 创建一个gerrit文件夹
  • 然后,我在我的主目录中创建一个具有相同文件夹的文件夹,然后使用&#34; git init&#34;将其转换为git repo。命令。
  • 然后,我将项目的所有内容复制到此文件夹中的gerrit存储库中,并使用&#34; git add --all&#34;将所有更改添加为新更改。命令
  • 我创建一个.gitreview文件并将主机和项目属性放入其中。
  • 提交我的更改。
  • 最后,我使用&#34; git review -R&#34;命令将我的更改发送到gerrit存储库以供审核。

在这里,在最后一步中,如果我使用此命令git push ssh://[username]@[ip]:29418/project_name,它可以工作。但在这种情况下使用gerrit存储库是没有意义的,因为我直接将它们推送到git而不进行任何审查。此外,我假设当我将这个项目克隆到另一台计算机并将我的更改发送到gerrit存储库时,我将不得不处理这个错误,所以如果我在上面知道我做错了什么会更好。

提前致谢

2 个答案:

答案 0 :(得分:1)

不是在新目录中执行git init并添加代码,我建议您克隆新的空的gerrit存储库并在那里进行更改。所以要修改你的步骤:

  1. 使用命令&#34; ssh -p 29418 user @ localhost gerrit create-project project_name&#34;
  2. 创建一个gerrit文件夹
  3. 克隆project_name:clone ssh:// user @ localhost:29418 / project_name
  4. 复制所需项目的所有内容和&#34; git add --all&#34;
  5. 创建.gitreview文件并将主机和项目属性放入其中
  6. 提交更改
  7. git review

答案 1 :(得分:0)

HEAD -> refs/publish/master (no common ancestry)的原因可能是因为master (local)尚未挂钩master (remote, usually: origion/master)。为确保这一点,您可以运行git config --list并查找:

branch.master.remote=origin
branch.master.merge=refs/heads/master

如果缺少这一点,您可以手动直接设置(最好不要):

git config --local branch.master.remote=origin
git config --local branch.master.merge=refs/heads/master

或更好地使用:

git branch --set-upstream-to=origin/master master

分支名称来自:

git branch --all
我的是:

$ git branch --all
* master
  remotes/gerrit/master
  remotes/origin/master