You want more fans, I want more stage
Nov. 12th, 2015 02:13 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
In a radical departure from asking people what they're wearing, I would now like to ask for help with git. If you don't understand the question, just be very grateful and move on ;-)
When an incoming git pull suffers a merge failure[*], why, why, does git decide to compound the problem by staging every modified file it can lay its grubby little paws on?
I assumed that if I started typing "why does git stage..." into Google it would auto-complete with all the various phrases distressed people all over the internet have typed in. It does not, and I can't find anyone writing about it. For bonus points, tell me how to stop it doing this - but I'll settle for understanding the rationale behind it!
[*] Which, if the two versions have changed lines anywhere near each other, it will
When an incoming git pull suffers a merge failure[*], why, why, does git decide to compound the problem by staging every modified file it can lay its grubby little paws on?
I assumed that if I started typing "why does git stage..." into Google it would auto-complete with all the various phrases distressed people all over the internet have typed in. It does not, and I can't find anyone writing about it. For bonus points, tell me how to stop it doing this - but I'll settle for understanding the rationale behind it!
[*] Which, if the two versions have changed lines anywhere near each other, it will
no subject
Date: 2015-11-12 03:02 pm (UTC)no subject
Date: 2015-11-12 03:08 pm (UTC)Though to be honest, I don't really like that behaviour either, since I usually end up resolving the conflict, staging the file to mark it resolved, and then un-staging it again.
Our of curiosity, what is your VCS of choice? As far as I can tell, everyone always hates the one they use :-)
no subject
Date: 2015-11-12 03:12 pm (UTC)git commit -a
) when you come to commit the merge? I'm getting the feeling that there's some extra part to your workflow that I don't understand, which needs things not to be staged for some other reason.I didn't find any option in
git help pull
to not scatter failed-merge detritus across the index, but I suppose if you wanted to just unstage everything after a failed merge then there's probably a fairly easygit checkout-index
rune.My VCS of choice is git :-) I've always felt that git is the anti-Marmite: the correct response is to both love and hate it, at the same time. When I have to use anything else, I wish it had all the advantages of git, but when I use git, I get annoyed with it constantly...
no subject
Date: 2015-11-12 03:26 pm (UTC)I read "I've not been with git since the beginning" as meaning "In the beginning I was with git, now I am not" rather than "I am with git, but was not at the beginning" so thought you'd moved on to something preferable. Or less hatable :)
no subject
Date: 2015-11-12 03:33 pm (UTC)no subject
Date: 2015-11-12 03:35 pm (UTC)no subject
Date: 2015-11-12 05:15 pm (UTC)Branch more. Merge more. Branches that are old enough to vote are The Devil no matter what VCS you're using.
Ok, so I have one that's six months old because Other People, but I fully accept that if I don't keep refreshing it from master I will be the one who is sad.
(Also, round here, people who emit thumping great merge-requests get them bounced.)
no subject
Date: 2015-11-12 07:07 pm (UTC)In my particular case, my long-term work is a large piece of work that will result in not a huge amount of code. And would be a lot less long-term if I didn't get interrupted by other things on a daily basis. So I don't think the merge will be all that horrible when it comes :-) I'm merging unrelated bits as I go.
But you're almost certainly correct that I should branch more.
no subject
Date: 2015-11-12 07:38 pm (UTC)That said, we used to have to cope with devs emitting vast diffs and then being surprised we got rather narky when the relevant website exploded. Once we allowed/made them their own deploys, it could all happen faster and so the diffs are (usually) smaller.
These days, we're one dev/ops amorphous blob, so you are allowed/expected to go 'Too many notes, Mozart. Make it simpler and show me the tests', which has make progress entirely not antagonistic.
Apart from one 'team' 'lead' on another floor, who really doesn't see why he should share with the other children. Boy howdy, he's going to find out how things work the hard way.. :)
no subject
Date: 2015-11-12 10:40 pm (UTC)no subject
Date: 2015-11-13 07:21 am (UTC)I am mostly afraid of everything with git. A typo or a not-very-well-understood command line can have such... surprising and far-reaching consequences :)
no subject
Date: 2015-11-13 08:11 am (UTC)no subject
Date: 2015-11-14 11:40 am (UTC)The help pages for this syntax are git-reflog and git-rev-parse.
no subject
Date: 2015-11-12 11:05 pm (UTC)That said, I think the thing I would suggest not doing is trying to do a merge when you have uncommitted local changes. If the merge doesn't work then things are going to get very confused between the changes in your working tree which need to be committed as part of the merge commit to resolve conflicts, and changes in your working tree which you didn't want to commit in the merge at all. (This is why git is staging modified files, I think -- it expects them to be modified because they're merge-conflicts that got resolved either automatically or manually.)
There are several ways you can avoid having uncommitted local changes when you merge. The simplest I think is to use 'git stash', which will let you squirrel away your local changes before trying a merge; then you can 'git stash pop' to reapply them afterwards (which might give conflicts that need resolving at that point, of course). Or you can go more serious and start maintaining your local changes as effectively a stack of patches in a set of git commits on a branch that you rebase onto the top of whatever upstream is now. (There are also extra tooling/wrapper scripts that can help with this; I use stgit and like it a lot because practically my whole interaction with git is "maintain, update and edit patch series". But it is a whole bunch of extra commands to get confused with, so I'm always slightly hesitant about recommending it to people.)
no subject
Date: 2015-11-13 07:23 am (UTC)Me: right, ready! Commit these files, and push them.
Git. No.
Me: Why not?
Git: New stuff in the repo. Try pulling.
Me: Oh, all right.
Git: Ha! Merge conflict, I've staged everything!
Me: Dammit, should have stashed.
Every so often I think I really should get to grips properly with git, but I always get instantly bogged down reading about it, because everything basically reads like this: http://git-man-page-generator.lokaltog.net/
no subject
Date: 2015-11-13 08:15 am (UTC)no subject
Date: 2015-11-13 08:22 am (UTC)no subject
Date: 2015-11-13 08:19 am (UTC)no subject
Date: 2015-11-13 08:22 am (UTC)no subject
Date: 2015-11-13 01:12 am (UTC)I use tortoisegit for a lot of my day to day git stuff, but for merges and diffs, we've set up beyond compare to do the changes. If you haven't used Beyond Compare or Tortoise git they are wonderful tools. Beyond compare is really useful when you are doing mass file comparrisons, eg working out what has changed on a website and which changes you want to bring across. Only downside is it defaults to timestamp rather than content comparrison but a quick change of the options of a compare does wonders.
https://www.youtube.com/watch?v=pp2S2lHjzZI
https://www.youtube.com/watch?v=eGAyWvstKCI
no subject
Date: 2015-11-13 07:27 am (UTC)Most of the time I'm dealing with tiny numbers of files at once (say <15) so doing things manually isn't really much of an issue. Thanks for the recommendations, though, I'll have a look!
no subject
Date: 2015-11-13 09:14 am (UTC)no subject
Date: 2015-11-13 10:03 am (UTC)no subject
Date: 2015-11-13 10:51 am (UTC)no subject
Date: 2015-11-13 11:18 am (UTC)no subject
Date: 2015-11-13 09:16 am (UTC)no subject
Date: 2015-11-13 04:27 pm (UTC)Occasionally I think that maybe I should be using a VCS instead of my horribly primitive habit of zipping complete source trees and archiving them. Reading about other people's VCS experiences is an important reminder of why I stopped using them. :-P
no subject
Date: 2015-11-13 07:14 pm (UTC)Since you are (I think?) largely working alone these days, zipping probably works fine :) Though when I finally get round to those website updates I'm meant to be doing, I had been considering using git just for ease of deploying files.
Also hello, I didn't think you read LJ any more!
no subject
Date: 2015-11-13 07:48 pm (UTC)no subject
Date: 2015-11-13 10:00 pm (UTC)Y'know, if all the people who said they miss LJ could be persuaded to come back, no-one would have to miss it :)
no subject
Date: 2015-11-13 10:12 pm (UTC)Some people write just to keep journals, which I respect, but I use social media mainly to communicate and that doesn't work well if nobody sees the posts. Crosslinking between services sort of works, but means everyone has to have accounts on both services or you can't lock stuff (not a problem, I usually post public) and the intended audience for posts on both has to overlap (is a problem for me).
no subject
Date: 2015-11-14 11:23 am (UTC)Oh yes, I wasn't blaming you for abandoning ship. Merely if some magic thing could persuade everyone who sporadically laments LJ's passing!
no subject
Date: 2015-11-14 09:15 am (UTC)If you don't want the scrappy intermediate commits which this would seem to imply being exposed when you eventually finish your work, there's several strategies, most of which I think will work best with the rebasing approach.
If you expect to submit it as a single commit you could either add all new work by amending a single commit (
git commit --amend
every time you commit anything), or you could squash it at the end (e.g. withgit merge --squash
when you're done).If it's more complex and ought to be several commits, but you don't necessarily know what they are yet, that's also possible to manage (pm's suggestion of stgit can achieve this, though it's not the only approach).