I have recently given commit access to LLVM and successfully pushed a test commit from my local master branch.
However, I can’t find which is the recommended workflow for committing more serious stuff using git alone. I have read the docs but everything seems to still require svn before bridging to github. I want to use git alone to commit a patch that I got reviewed.
I currently have a local 'master' branch that I keep identical to the upstream branch. I also have another local branch (let's call it 'patchbranch' for the purposes of this question) where I committed the changes for the patch I want to push. I created the diff file by running git diff to compare my local 'master' with 'patchbranch’ branches and uploaded the file to Phabricator. I got the patch reviewed and I want to commit it now to the upstream master. I make sure my 'patchbranch' catches all the upstream changes by pulling from 'master', merging 'master' into my 'patchbranch and running the relevant tests.
I want to push my local 'patchbranch' to the upstream ‘master’ in GitHub without affecting my local master branch. I also need to make sure that my patch is pushed as a single commit. I do not want to merge my local 'patchbranch' into my local 'master' because I want to keep my local 'master' clean and always identical to, or only slightly behind, the upstream branch.
I have read the documentation but all the described workflows seem to imply the use of svn at some point, which I do not want to, or know how to use. I understand this is a basic question but I used git before with small teams only, so a detailed workflow for LLVM commits using git alone would be appreciated.
Thanks,
John
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Thanks for your reply, but if I understand it well, this implies making changes to the local ‘main’ branch, and push from that, which is what I want to avoid. But still, if I push from ‘main’, how do I fold a number of local commits into a single one, with a single comment, as appropriate for LLVM?.
My workflow consists on creating different local branches to avoid changes on the ‘main’ branch. This allows me a couple of things: First, I always keep my local ‘main’ branch in sync with the remote one, so it’s very easy to spot differences with my working ones by just running diff between them. Second, I can do an undo things, or test them in my working branches as many times as I want and commit often. I can even start from scratch from main again by just creating a new branch from that, without ever messing with the ‘main’ branch. Also, separating work into branches allows for implementing another patch while a previous one is waiting review, (while still never touching ‘main’).
In the past, I worked using a similar environment on a small team. Everyone's local changes were pushed to the remote repo at the end of the day by first merging into our local ‘main’ and then pushing to the remote ‘master’. This works on a small team because it doesn’t matter if a number of local commits get pushed together. Also everybody is happy to fix conflicts created by others if they happen, as there’s no ‘reviews’ to begin with.
In the case of LLVM it’s desirable that every reviewed patch is pushed as a single commit with the appropriate comment. Ideally, I would want to commit and push the difference between a local working branch and the ‘main’ branch, which is what I can’t figure out how do do. I would be surprised if there’s not a simple solution for that.
Thanks.
John
> On 8 Nov 2019, at 16:24, Blower, Melanie <melanie...@intel.com> wrote:
>
>
>
>> -----Original Message-----
>> From: llvm-dev <llvm-dev...@lists.llvm.org> On Behalf Of Joan Lluch via
>> llvm-dev
>> Sent: Friday, November 8, 2019 6:35 AM
>> To: llvm-dev <llvm...@lists.llvm.org>
>> Subject: [llvm-dev] Workflow to commit changes using git alone (?)
>>
>> Hi all,
>>
>> I have recently given commit access to LLVM and successfully pushed a test
>> commit from my local master branch.
>>
>> However, I can’t find which is the recommended workflow for committing more
>> serious stuff using git alone. I have read the docs but everything seems to still
>> require svn before bridging to github. I want to use git alone to commit a patch
>> that I got reviewed.
> [Blower, Melanie]
> I recently made my first commit to llvm using git, I can't speak to whether this is recommended flow. First get code review and approval, then:
> git clone https://github.com/llvm/llvm-project.git ## get the llvm tree
> ## apply your patch, test your patch
> Git add ... files
> Git commit ... commit message should include url to the phabricator review
> Git pull --rebase ## if your clone is behind master, do this to pull in the changes neatly
> Git push ## This will prompt you to provide github identity
I would have hoped for a more automatic way, but I will give “--amend” a try.
Thanks for that!
John
> On 8 Nov 2019, at 17:36, Blower, Melanie <melanie...@intel.com> wrote:
>
>
>
>> -----Original Message-----
>> From: Joan Lluch <joan....@icloud.com>
>> Sent: Friday, November 8, 2019 11:29 AM
>> To: Blower, Melanie <melanie...@intel.com>
>> Cc: llvm-dev <llvm...@lists.llvm.org>; Sanjay Patel <spa...@rotateright.com>
>> Subject: Re: [llvm-dev] Workflow to commit changes using git alone (?)
>>
>> Hi Melanie,
>>
>> Thanks for your reply, but if I understand it well, this implies making changes to
>> the local ‘main’ branch, and push from that, which is what I want to avoid. But
>> still, if I push from ‘main’, how do I fold a number of local commits into a single
>> one, with a single comment, as appropriate for LLVM?.
> [Blower, Melanie] I'm not a sophisticated git user, but I do know how to fold local commits.
> % git commit --amend
> Assuming your workspace has several commits and you want to compress then into 1 before push
> This is an interactive process, git will pop you into an editor, maybe 'vi' with a bunch of SHA codes listed. What I do is,
> Keep the top line unmodified, on subsequent lines use the 's' letter to indicate that you want to squash it into the previous
> After you write out the file that git put you into, it will prompt you again to finalize the commit message for the compressed commit. It's all local so you can give it a try.
Ok, just for the matter of providing feedback that may be useful for others, I figured out one way to do it based on the setup that I described earlier. It can be something like this
git checkout patchbranch # checkout to the patch branch, this is the one containing the differential patch code
git checkout -b tmp # checkout to a new tmp branch
git reset —soft master # set the tmp head to the master head without touching any files, so now the next commit will contain the delta from master
git commit # commit the delta from master, this is the where to add the required commit message and the 'Differential Revision' URL
git push origin tmp:master # push the tmp branch to the remote ‘master’ branch
(the tmp branch can be deleted now as it will have no more use)
Now, if the master to patchbranch diff has been properly submitted to Phabricator, all the steps above except the last one can be replaced by executing this:
git checkout master
arc patch D<revision>
According to the docs, "this will create a new branch called arcpatch-D<Revision> based on the current master and will create a commit corresponding to D<Revision> with a commit message derived from information in the Phabricator review"
This also sets the current branch to arcpatch-D<Revision>, so the only remaining thing to do is pushing the changes to the remote master:
git push origin arcpatch-D<Revision>:master
That’s all. The git system will inform whether there’s been another commit being pushed while preparing this one, in such case it would require to start over with a fresh pull from master
John
> On 8 Nov 2019, at 17:48, Blower, Melanie <melanie...@intel.com> wrote:
>
> No doubt there's a way that's not interactive. There's a free online copy of the "pro git" tome online, for what it's worth!
Hi All,
Ok, just for the matter of providing feedback that may be useful for others, I figured out one way to do it based on the setup that I described earlier. It can be something like this
git checkout patchbranch # checkout to the patch branch, this is the one containing the differential patch code
git checkout -b tmp # checkout to a new tmp branch
git reset —soft master # set the tmp head to the master head without touching any files, so now the next commit will contain the delta from master
On 10 Nov 2019, at 07:00, Mehdi AMINI <joke...@gmail.com> wrote:recipe is not correct in the absolute: the delta from master does not mean it contains exactly what you want, you seem to assume that master didn't evolve between the time "patchbranch" was created.
On 10 Nov 2019, at 07:00, Mehdi AMINI <joke...@gmail.com> wrote:recipe is not correct in the absolute: the delta from master does not mean it contains exactly what you want, you seem to assume that master didn't evolve between the time "patchbranch" was created.Hi Mehdi,I’m doing it this way to make sure that master /actually/ contains “exactly what I want” (!). Of course the remote master could have evolved slightly during such steps
, but that’s a cat-and-mouse game, that I don’t think that can be easily avoided (at least to my knowledge): We use Phabricator to get patches reviewed and this implies that new commits should be based on what we post there. If master has evolved significantly since the review, then a patch update should be sent to Phabricator anyway for further review. Also tests must be run again while master continues evolving. Ultimately, the commit that gets sent to Github must be strictly based on what we got reviewed on Phabricator. My procedure only attempts to enforce that the ‘delta’ commit that I push is predictable, and exactly the one that I previously posted on Phabricator.The procedure stated on the docs https://llvm.org/docs/Phabricator.html#committing-a-change suggests using ‘arcanist’ to create a ‘diferential’ branch based on master and the Phabricator revision number. The 'arc patch’ command is used for that. To my understanding, the problem is the same: creating that branch may take a few seconds, and while doing so, master can evolve too. The docs even suggest re-running the tests before pushing, which gives even more time for master to have changed.
(Said that, maybe I’m not fully getting ‘git', because I only used it in the past with small teams and no need for cross-reviews, so everything was pretty straightforward: pulling what others did, merging working branches with master, eventually resolving conflicts, and then pushing)Since you suggest that my “recipe” is not correct, I would appreciate that you elaborate on the correct one, which is why I opened this subject to begin with.
On 10 Nov 2019, at 20:27, Mehdi AMINI <joke...@gmail.com> wrote:No: the arcanist command does not suffer from the problem I was raising.The issue I was referring to is that your reset command will lead to *undoing* changes from master (unrelated to your branch) when you commit in the end (all the changes that are in master but not in "patchbranch").(just try to add `git checkout master && git pull && git checkout tmp` before your `git reset `, and then look at the resulting commit).
Hi Mehdi,On 10 Nov 2019, at 20:27, Mehdi AMINI <joke...@gmail.com> wrote:No: the arcanist command does not suffer from the problem I was raising.The issue I was referring to is that your reset command will lead to *undoing* changes from master (unrelated to your branch) when you commit in the end (all the changes that are in master but not in "patchbranch").(just try to add `git checkout master && git pull && git checkout tmp` before your `git reset `, and then look at the resulting commit).But I would never do that!. The commands "git checkout master && git pull” are only run before the whole procedure, never in the middle.
And the patchbranch is always merged with master before starting the procedure.
The Phabricator diff is created by comparing both branches after they have merged, and the point of reseting ’tmp' to ‘master’ is to obtain a fresh commit containing exactly the same diff.
In any case, I would want to understand why the archaist command does not suffer from an “evolving” master, which is the problem that you raised first. The “arc patch” command creates a new branch from the local master, so the remote repo can still have changed even before the actual command is completed (!) or at any time after that. So what makes executing that command different?, or maybe I should ask, what is the archaist command actually doing in terms of plain git commands?
If you have a local `patch branch` branch for your work, *and* you guarantee that your local master branch never ever diverge separately, then why do you need another branch in the first place. I may be missing some key part of your workflow.
On 11 Nov 2019, at 18:18, Hiroshi Yamauchi <yama...@google.com> wrote:I use 'arc diff' to upload a patch to Phabricator, which I think adds the Differential Revision url to the commit message.