简体   繁体   English

git-p4并从其他存储库中提取

[英]git-p4 and pulling from other repos

I have a laptop and a desktop, for which I'm trying to learn to use git to manage my work against a perforce repository. 我有一台笔记本电脑和一台台式机,为此,我试图学习使用git来针对perforce存储库管理我的工作。 I'm using git-p4 successfully on the desktop, and can use it successfully on the laptop as well, in isolation. 我在桌面上成功使用了git-p4,并且可以单独在笔记本电脑上成功使用它。 However, one of the things I'd like to be able to do is to "pull" or "push" changes from the laptop to desktop or vice versa without first checking them in to the p4 branch being synced with git. 但是,我想做的一件事情是将更改从笔记本电脑“拉”或“推”到台式机,反之亦然,而无需先将它们检入与git同步的p4分支中。

So, here's what I did to setup the two repos: 1) setup a repo on my desktop using git-p4 clone. 因此,这是设置两个存储库的操作:1)使用git-p4克隆在桌面上安装存储库。 Do some work on it, make several commits to git, and several submits to git-p4. 做一些工作,对git进行几次提交,对git-p4进行几次提交。 All was working as expected. 所有人都按预期工作。 2) later, set up a repo on my laptop, in prep for doing work on both machines. 2)之后,在我的笔记本电脑上设置一个存储库,以准备在两台计算机上进行工作。 Similarly, use git-p4 to do a clone of the now current p4 repo (now has several revisions checked in past where I did the git-p4 in (1). 类似地,使用git-p4克隆当前最新的p4存储库(现在已经检查了几个修订版本,而我在(1)中做了git-p4的地方)。

Now, what I was hoping to do: 1) do some work on the desktop. 现在,我希望做的是:1)在桌面上做一些工作。 Commit the work to git, but not p4. 将工作提交给git,但不提交给p4。 2) go to the laptop, and do a git pull ... from the desktop repo. 2)转到笔记本电脑,然后从桌面存储库中执行git pull...。 3) continue my work on the laptop, commiting to git periodically. 3)继续在笔记本电脑上工作,并定期执行git。 4) (optional) commit to p4 from the laptop 5) (optional) push to the desktop (or pull from the laptop to the desktop) and continue work on the desktop, etc. 4)(可选)从笔记本电脑提交到p4 5)(可选)推到桌面(或从笔记本电脑拉到桌面)并在桌面上继续工作,依此类推。

Basically, I'd like to be able to push/pull stuff back & forth between the laptop and desktop without actually checking in to p4. 基本上,我希望能够在笔记本电脑和台式机之间来回推拉东西,而无需实际登录p4。

Does this sound like something that should be possible? 这听起来像应该可行吗? If so, are there steps that I'm doing wrong above? 如果是这样,上面是否有我在做错的步骤?

Here's what keeps happening: when I try to do the "pull" in (2) above, I get error messages saying that there are conflicts - and these conflicts are related to changes that were made between the first checkouts of p4's branch, and the time the second git-p4 repo was created. 这是不断发生的情况:当我尝试执行上面的(2)中的“拉”操作时,我收到一条错误消息,指出存在冲突-这些冲突与p4分支的第一个签出之间的更改有关,并且创建第二个git-p4存储库的时间。 In other words, they seem to be replay's of changes that should have already been in the code that the second repo contained, but for some reason, they weren't. 换句话说,它们似乎是更改的重播,这些更改本来应该在第二个存储库所包含的代码中进行的,但是由于某些原因,事实并非如此。

I'm pretty new to git, so I hope my question isn't crazy stupid or impossible to understand. 我对git还是很陌生,所以我希望我的问题不是疯狂的愚蠢或无法理解。 Thanks in advance for any help you can give. 在此先感谢您提供的任何帮助。

The problem is that your two repositories (desktop and laptop) don't realize that they are related to one another through Perforce. 问题是您的两个存储库(台式机和笔记本电脑)没有意识到它们通过Perforce相互关联。 The normal git-p4 clone will take from top-of-tree and, as such, you will wind up with different commit identifiers for identical changes. 普通的git-p4克隆将从树的顶部获取,因此,您将为相同的更改使用不同的提交标识符。 This is because a git "commit" includes information about its parents. 这是因为git“提交”包含有关其父级的信息。

The simplest solution is to work as follows: 最简单的解决方案是按以下方式工作:

  1. Create the git-p4 clone on your desktop. 在桌面上创建git-p4克隆。
  2. git clone from your desktop to your laptop. git clone从桌面git clone到笔记本电脑。

Now, both your laptop and your desktop will have a common history from Perforce. 现在,您的笔记本电脑和台式机都将具有Perforce的共同历史记录。 (You can verify this by seeing that the commit identifiers were different in git log before but after these two steps, should be the same.) (您可以通过在这两个步骤之前和之后的git log查看提交标识符是否不同来验证这一点)。

After this point, you should be able to pull between the two repositories without conflicts. 在这之后,您应该能够在两个存储库之间切换而不会发生冲突。

In fact, you will be able to git p4 sync or git p4 rebase in either place as well, because git-p4 is smart enough to detect the other's work and continue. 实际上,您也可以在任一位置进行git p4 syncgit p4 rebase ,因为git-p4足够聪明,可以检测到对方的工作并继续。 Your laptop will also try to git pull from the origin server (your desktop) if it can, if I recall correctly. 如果可以的话,如果我没记错的话,您的笔记本电脑还将尝试从原始服务器(您的台式机)上进行git pull

Two other bits of advice: 其他两点建议:

  • Don't use git push between these two repositories. 在这两个存储库之间不要使用git push It is generally unsafe to push to non-bare repositories , ie, those repositories that having working trees, such as the ones you have described here. 推送到非裸存储库通常是不安全的,即具有工作树的存储库,例如您在此处描述的存储库。 If you do such a push, then the index will be different than the working tree and things like git status (and hence git commit , etc.) will not work the way you expect. 如果您进行这种推送,则索引将不同于工作树,并且git status类的东西(因此git commit等)将无法按您期望的方式工作。
  • Keep Perforce on a separate branch (I use master ) and do all your development on topic branches. 将Perforce放在单独的分支上(我使用master ),并在主题分支上进行所有开发。 Pull only to these branches. 只拉到这些分支。 When you do a git p4 sync or rebase , switch back to your master branch. 当您执行git p4 syncrebase ,请切换回您的master分支。 Then do merges from master down to your topic branch. 然后从master向下合并到您的主题分支。 This helps keep the upstream history very clear and separate from the work you are doing in git. 这有助于使上游历史记录非常清晰,并与您在git中所做的工作分开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM