[llvm-dev] Workflow to commit changes using git alone (?)

Joan Lluch via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 8 15:32:44 PST 2019


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
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.blower at 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!
> 
>> -----Original Message-----
>> From: Joan Lluch <joan.lluch at icloud.com>
>> Sent: Friday, November 8, 2019 11:46 AM
>> To: Blower, Melanie <melanie.blower at intel.com>
>> Cc: llvm-dev <llvm-dev at lists.llvm.org>; Sanjay Patel <spatel at rotateright.com>
>> Subject: Re: [llvm-dev] Workflow to commit changes using git alone (?)
>> 
>> 
>> Hi Melanie,
>> 
>> 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.blower at intel.com>
>> wrote:
>>> 
>>> 
>>> 
>>>> -----Original Message-----
>>>> From: Joan Lluch <joan.lluch at icloud.com>
>>>> Sent: Friday, November 8, 2019 11:29 AM
>>>> To: Blower, Melanie <melanie.blower at intel.com>
>>>> Cc: llvm-dev <llvm-dev at lists.llvm.org>; Sanjay Patel
>>>> <spatel at 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.
>>>> 
>>>> 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.blower at intel.com>
>>>> wrote:
>>>>> 
>>>>> 
>>>>> 
>>>>>> -----Original Message-----
>>>>>> From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Joan
>>>>>> Lluch via llvm-dev
>>>>>> Sent: Friday, November 8, 2019 6:35 AM
>>>>>> To: llvm-dev <llvm-dev at 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 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-dev at lists.llvm.org
>>>>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>> 
> 



More information about the llvm-dev mailing list