views:

643

answers:

1

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. I'm using git-p4 successfully on the desktop, and can use it successfully on the laptop as well, in isolation. 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.

So, here's what I did to setup the two repos: 1) setup a repo on my desktop using git-p4 clone. Do some work on it, make several commits to git, and several submits to git-p4. All was working as expected. 2) later, set up a repo on my laptop, in prep for doing work on both machines. 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).

Now, what I was hoping to do: 1) do some work on the desktop. Commit the work to git, but not p4. 2) go to the laptop, and do a git pull ... from the desktop repo. 3) continue my work on the laptop, commiting to git periodically. 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.

Basically, I'd like to be able to push/pull stuff back & forth between the laptop and desktop without actually checking in to 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. 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. Thanks in advance for any help you can give.

+4  A: 

The problem is that your two repositories (desktop and laptop) don't realize that they are related to one another through 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. This is because a git "commit" includes information about its parents.

The simplest solution is to work as follows:

  1. Create the git-p4 clone on your desktop.
  2. git clone from your desktop to your laptop.

Now, both your laptop and your desktop will have a common history from 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.)

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. Your laptop will also try to git pull from the origin server (your desktop) if it can, if I recall correctly.

Two other bits of advice:

  • Don't use git push between these two repositories. It is generally unsafe to push to non-bare repositories, i.e., 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.
  • Keep Perforce on a separate branch (I use master) and do all your development on topic branches. Pull only to these branches. When you do a git p4 sync or rebase, switch back to your master branch. Then do merges from master down to your topic branch. This helps keep the upstream history very clear and separate from the work you are doing in git.
Emil