0

我正在尝试了解 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'*

在执行以下步骤后出现此错误;

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

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

提前致谢

4

2 回答 2

1

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

  1. 使用命令“ssh -p 29418 user@localhost gerrit create-project project_name”创建一个gerrit文件夹
  2. 克隆项目名称:克隆 ssh://user@localhost:29418/project_name
  3. 复制你想要的项目的所有内容和“git add --all”
  4. 创建一个 .gitreview 文件并将主机和项目属性放入其中
  5. 提交更改
  6. git 审查
于 2016-02-12T17:13:50.193 回答
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
于 2018-03-14T08:59:13.763 回答