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

Christopher Degawa via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 8 17:57:01 PST 2019


As a person who uses git almost exclusively, your workflow is
needlessly confusing

You should almost never push to your GitHub master unless you are updating
from upstream or it's your own project and you are developing it

I am excluding commands relating to archaist since I don't understand it
and can't figure out how to use Phabricator at all.
I will use `upstream` to represent the llvm-project remote (
https://github.com/llvm/llvm-project.git), and `origin` to represent my
personal fork

``` bash
git fetch --all -pf
# Make sure you have updated all of remote branches

git checkout patchbranch
git checkout -b tmp
git rebase -i $(git merge-base HEAD upstream/master)
# Runs a rebase on from the commit you branched off that exists in the
master branch of llvm. This should be clean as it would only apply changes
you have made since you last checked from master
# An editor should open and you can replace all of the `pick`s after the
first commit with either `fixup` if you don't care about what message you
had, `squash` if you just want to combine the commits but keep the message
# Or `reword` if you want to edit the message. You must have a `pick` at
the top.
# In your case, I would just recommend to stick with either squashing or
`fixup` on all of the commits except the first one

git rebase -i upstream/master
# This time rebase onto llvm-project master to make sure it will cleanly
apply. Do the same here if necessary
# If you get any conflicts, you will need to resolve them. Just goto the
file that it says conflicted and look for <<<<<<< and >>>>>>> lines.
# The <<<<<<< to ======= lines are the lines currently in llvm-master. The
======= to >>>>> lines are the ones you have modified in your commit.
# You will need to remove the <, =, and > lines based on what you want to
change
# Remove from ==== to >>>> if you want to discard your changes, <<<< to
==== if you want to keep yours, or potentially just remove the <=> if you
want both.

# Run the following if you had conflicts
git add <conflicting file(s)>
git rebase --continue

# push to your fork
git push -u origin tmp # add -f if you already had a tmp branch in your
online fork

# Later on, if you want to delete the branch
git checkout master
git branch -D tmp
git push --delete origin tmp
```

For others
``` bash
# If you need to generate a patch file that can be accepted by `git am`.
You can also apply -U9999 if you really want to.
git format-patch upstream/master

# If you want a simple diff file without commit information etc. Unless you
git diff upstream/master > changes.diff

# Both formats of .diff and .patch are accepted by `git apply` or `patch
-p1 ...` and are accepted by differential.
```

After review
``` bash
arc patch D#####
git branch # Confirm you are on arcpatch-D#####
git push upstream HEAD:master # or wherever.
```

Note: I'm using the github markdown format of ``` to represent a code block
and ` to represent a code or single line to be considered separate, so
mentally strip those when reading them


On Fri, Nov 8, 2019 at 6:33 PM Joan Lluch via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> 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
> >>>
> >
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191108/74dc377e/attachment-0001.html>


More information about the llvm-dev mailing list