FHIR Chat · Git won't switch · committers/git-help

Stream: committers/git-help

Topic: Git won't switch


view this post on Zulip Grahame Grieve (Oct 11 2018 at 05:57):

My ongoing journey of mutual antagonism with git is reaching new highs. or lows. Or whatever.

view this post on Zulip Grahame Grieve (Oct 11 2018 at 05:58):

I have a huge set of changes I've made and I'm trying to switch between branches so I can commit them piecemeal.

view this post on Zulip Grahame Grieve (Oct 11 2018 at 05:59):

if I just switch between new branches, the new branches seem to aggregate the changes across them (check out https://github.com/HL7/fhir/pull/72 and then https://github.com/HL7/fhir/pull/73

view this post on Zulip Grahame Grieve (Oct 11 2018 at 06:00):

so I decide to switch back to master between commits. Though I HATE doing that because git will take it upon itself to 'remove' files from my workspace that it decides (on my behalf) I no longer need . but what else can I do?

view this post on Zulip Grahame Grieve (Oct 11 2018 at 06:02):

but it won't let me switch back to master because I have a conflict. I must commit or stash. Well, I don't want to do either of those things. I want to know what the hell has changed before I try to figure it out. In fact, I don't want to do either of those. I want to merge my changes maybe. I don't know why the hell it thinks there's a clash anyway. I'm the only one making changes right now. Guess they're more manufactured clashes.

view this post on Zulip Grahame Grieve (Oct 11 2018 at 06:02):

anyway, after reading, I see that I should do git.exe checkout --merge master --

view this post on Zulip Grahame Grieve (Oct 11 2018 at 06:02):

ok. so then I get

view this post on Zulip Grahame Grieve (Oct 11 2018 at 06:02):

M   implementations/java/org.hl7.fhir.r4/src/org/hl7/fhir/r4/terminologies/CodeSystemUtilities.java
M   implementations/java/org.hl7.fhir.r4/src/org/hl7/fhir/r4/utils/NarrativeGenerator.java
M   implementations/java/org.hl7.fhir.r4/src/org/hl7/fhir/r4/utils/ToolingExtensions.java
M   source/codesystem/codesystem-extensions-spreadsheet.xml
M   source/codesystem/codesystem-notes.xml
M   source/snomed/snomed.xml
M   source/valueset/valueset-designation-use.xml
M   tools/java/org.hl7.fhir.tools.core/src/org/hl7/fhir/tools/converters/ValueSetImporterV3.java
M   tools/java/org.hl7.fhir.tools.core/src/org/hl7/fhir/tools/publisher/Publisher.java
M   vscache/ucum.cache
Your branch is behind 'origin/master' by 4 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Switched to branch 'master'
Has merge conflict

view this post on Zulip Grahame Grieve (Oct 11 2018 at 06:02):

Has merge conflict

view this post on Zulip Grahame Grieve (Oct 11 2018 at 06:03):

thank you for telling me where the merge conflict is...

view this post on Zulip Grahame Grieve (Oct 11 2018 at 06:03):

could this experience be any worse?

view this post on Zulip Grahame Grieve (Oct 11 2018 at 06:07):

error: Your local changes to the following files would be overwritten by merge

view this post on Zulip Grahame Grieve (Oct 11 2018 at 06:07):

could you just let me know what those changes might be so I can make decisions about them? How the hell is this supposed to work?

view this post on Zulip Grahame Grieve (Oct 11 2018 at 06:10):

I give up. commit everything for the sake of my sanity.

view this post on Zulip Grahame Grieve (Oct 11 2018 at 07:09):

really, it's very simple, what I want to do:

  • create a new branch off master
  • cherry pick a few files out of my working directory and commit them to the new branch
  • then push that up to the origin, and do a PR up on the origin
  • and to do all that without touching any files in my directory.

And while this sounds simple, GIT instead offers a myriad of workflow choices for not quite doing that list, because all the options come back to the one hard fact: it will change the files in my local directory whatever I try and do. Which is the one thing I do not want to happen

view this post on Zulip Bryn Rhodes (Oct 11 2018 at 14:10):

What client are you using?

view this post on Zulip Joel Schneider (Oct 11 2018 at 14:49):

maybe try git checkout --merge

view this post on Zulip Josh Mandel (Oct 11 2018 at 14:55):

I'd be careful with "checkout --merge master" because it'll get you out of alignment with the master branch at the origin.

view this post on Zulip Josh Mandel (Oct 11 2018 at 15:01):

Fundamentally the ability to change branches without changing your working tree isn't something that's going to make you happy in git. There are ways to do various pieces of this (e.g., https://stackoverflow.com/a/15993574) but if you're not following all of the implications, you're pretty likely to get mixed up.

view this post on Zulip Josh Mandel (Oct 11 2018 at 15:03):

I'd recommend just creating a new directory next to your main checkout (and probably "git remote add mainwork ../path/to/main/work"). Then you can "git fetch mainwork" and cherry pick as needed.

view this post on Zulip Lloyd McKenzie (Oct 11 2018 at 15:05):

Except that in the FHIR source, files are organized into 150+ sub-folders. Are you saying to create a clone of the whole FHIR source that only contains your changes?

view this post on Zulip Josh Mandel (Oct 11 2018 at 15:10):

A clone is a whole directory, containing the repo. Is this a concern for some reason?

view this post on Zulip Lloyd McKenzie (Oct 11 2018 at 15:12):

Having 2 full copies of the repository and sometimes working in one, sometimes working in the other doesn't sound like a recipe for good things

view this post on Zulip Josh Mandel (Oct 11 2018 at 15:29):

To be clear, I'm describing a workflow for Grahame -- not recommending this as a general practice.

view this post on Zulip Josh Mandel (Oct 11 2018 at 15:29):

And with the ability to fetch from a local clone using the git primitives, it's possible to manage this pretty well (just like working with any other remote).

view this post on Zulip Grahame Grieve (Oct 11 2018 at 16:46):

Is this a concern for some reason

it feels wrong. it's prone to introduce it's own mistakes. And it takes time and disk space. But it looks like the least worst option.

if you're not following all of the implications, you're pretty likely to get mixed up

The current workflow mixes me up. Once I commit something for a PR, i can either

  • not do anything else until the PR is merged and I can switch back to master and get my code when I update from the master
  • lose the code while I work on something else

Maybe git works for people who just don't do more than one thing at a time, I don't know. but I can't manage the workflow at the moment.

view this post on Zulip Grahame Grieve (Oct 11 2018 at 16:46):

I think I'm just going to commit only from a clone of the directory that I don't use. When I heard of this idea, I though it was astonishingly bad. But apparently this counts as state of the art in version control

view this post on Zulip Grahame Grieve (Oct 12 2018 at 05:25):

using a clone directory is worse. you gradually build up a long list of changed files, and git doesn't know that they're actually committed. I ended up reverting everything. after going through with a toothpick to make sure I had committed everything from the clone directory.

view this post on Zulip Grahame Grieve (Oct 12 2018 at 05:31):

my conclusion is that I'm not clever enough to be able to use git with branching to support my standard workflow. It seems to me that I have to expect a 30-40% hit on my upper throughput from now on

view this post on Zulip Grahame Grieve (Oct 12 2018 at 05:31):

and also say good by to granular commits that match the scope of an individual task

view this post on Zulip Grahame Grieve (Oct 12 2018 at 05:32):

maybe i do want to go back to svn. these are mighty big impacts to deal with

view this post on Zulip Grahame Grieve (Oct 12 2018 at 06:03):

or maybe I'd like to stick with git but not use branching. And not have a checked build :-(

view this post on Zulip Grahame Grieve (Oct 12 2018 at 10:59):

say good by to granular commits that match the scope of an individual task

view this post on Zulip Grahame Grieve (Oct 12 2018 at 11:00):

no. I investigated that further. git gives me this on commit: 3bc7e30d09

view this post on Zulip Grahame Grieve (Oct 12 2018 at 11:00):

and this works: https://github.com/HL7/fhir/commit/3bc7e30d09

view this post on Zulip Lloyd McKenzie (Oct 12 2018 at 14:05):

Does the "one branch per user" solution not work?

view this post on Zulip Lloyd McKenzie (Oct 12 2018 at 14:06):

That should let you commit what you like, push it and merge it in discrete build. It means you can't do a local commit until you're ready to push something to the server, but that's not different from how we'd behave under SVN.

view this post on Zulip Grahame Grieve (Oct 12 2018 at 18:25):

well, I'll give it a go and see

view this post on Zulip Grahame Grieve (Oct 13 2018 at 03:57):

well, ok. so i'm working in my branch, and I have a bunch of things going on... how do I sync with the master?

view this post on Zulip Lloyd McKenzie (Oct 13 2018 at 14:14):

Do a merge. You can select "master" as the remote branch to merge in.

view this post on Zulip Rob Hausam (Oct 13 2018 at 14:25):

If you've updated your local master branch (typically by doing git pull when you've checked out master, which will fast-forward update it if you've kept it "clean"), then when you've checked out and switched back to your working branch you can do git merge master (as Lloyd says). You might occasionally have a conflict with that if someone else has made changes in the same file(s) you are working on, but usually it should merge cleanly.

view this post on Zulip Lloyd McKenzie (Oct 13 2018 at 14:26):

You can't update your local master branch if you don't want to switch out of your changes branch.

view this post on Zulip Lloyd McKenzie (Oct 13 2018 at 14:27):

But you can merge remote/master directly into your changes branch

view this post on Zulip Rob Hausam (Oct 13 2018 at 14:36):

Yes, I agree. If you haven't first pulled to your local master then you'll have to merge from the upstream master. I think that may get trickier in the long run. But if we're talking about a "one branch" workflow where you do all of your work in a single local branch and you never use multiple feature branches, then you would obviously do that. What I'm suggesting is that if you do use multiple branches, then I think it will be best to always pull from the upstream master into only one of the local branches (and a clean master may be the easiest choice). But, as we've already heard, there are many "right" (or at least not wrong) ways to do this.

view this post on Zulip Lloyd McKenzie (Oct 13 2018 at 18:28):

Grahame's work process doesn't seem to lend itself to multiple branches. So we need to answer based on what the recommended path is for Grahame - which is one branch where he does all his work from - and he never bothers to switch to his local master. In fact, he should never need to switch at all.

view this post on Zulip Lloyd McKenzie (Oct 13 2018 at 18:28):

(after he's in his "grahame" branch)

view this post on Zulip Grahame Grieve (Oct 14 2018 at 21:38):

ok so check https://github.com/HL7/fhir/pull/98

view this post on Zulip Grahame Grieve (Oct 14 2018 at 21:39):

you'll see that the pull request lists a list of commits... about 2/3 of those commits were in my previous PR, and are not committed. So my long running branch is going to get ever more diverted..

view this post on Zulip Lloyd McKenzie (Oct 14 2018 at 21:56):

Have you merged remote master into your local branch?

view this post on Zulip Grahame Grieve (Oct 14 2018 at 21:57):

yes


Last updated: Apr 12 2022 at 19:14 UTC