Mr. Fegur
Mr. Fegur

Reputation: 797

git-p4 How to fetch a changelist

git p4 submit --shelve takes your committed changes in the local git repo and puts them in a changelist X and shelves them.

Let's say I did some code reviews on the shelved changes, and so the files in my local git repo are not the same as the files in the changelist X. How do I get the updates in changelist X into my local git repo?

Upvotes: 4

Views: 1749

Answers (2)

Chris
Chris

Reputation: 1697

I made a modified version of git-p4.py to kind of support this. You create a file that has the change numbers of each of your shelved changelists. Then you just run git p4 sync --changesfile <filename>.

The only problem is that this will import the changes into your p4/master branch, so git-p4 will think those changes are already submitted. If you use it, you'd have to do a hard-reset of some local git branch to the newly-imported commits, then hard-reset the p4/master ref back to what it was before the import. It also adds the [git-p4: depot-paths = ...] info to the bottom of the commit message, so it isn't fit for running git p4 submit directly. You could probably write some kind of git commit filter to strip those in batch.

Nonetheless, I think it is way better than dealing with p4 unshelve, p4 diff -dau > foo.patch, and patch -Npx -i manually.

Upvotes: 1

jamesdlin
jamesdlin

Reputation: 90105

You could generate a diff and then apply it to your git tree. (The easiest and most reliable way to generate a diff probably would be to unshelve the changeset into a clean Perforce client and to then do p4 diff -du .... Note that this won't work on added or deleted files, however.)

In the future, you should avoid needing to do this. The point of using git-p4 in the first place is to work primarily with git but to sync changes to and from Perforce. Your git environment therefore should be your "master" environment, and your Perforce client should be used as just a staging area to the Perforce server.

Upvotes: 0

Related Questions