News for hackers. Stuff that matters.
Re:Git add -p: a powerful git feature by daveungerer on Monday November 05, 2012 @04:01PM (#4745777)
Or you could just use a GUI app and save yourself a lot of time. SourceTree (OS X only, free - http://sourcetreeapp.com) has changed the way I use git since I started using it a few weeks ago.

The best thing is the discoverability - you don't need to know about the -p flag, for instance, since it's handled by the UI. Same for many other useful git commands that are hard to remember - they are often a simple option on a right-click menu, or a checkbox when performing an operation.

Re:Git add -p: a powerful git feature by johnkary on Monday November 05, 2012 @04:28PM (#4745892)
I never advocate GUIs as the primary means by which a developer works with version control. Sure it might be OK for some things like browsing history (GitX) but most GUIs often abstracts away much of the underlying complexity, which is absolutely great if you're a designer without much command-line experience, but absolutely a disservice to your in-depth knowledge as a developer and the tools you rely on every day.

If you write code day in day out you SHOULD be comfortable on the command-line. That's why I highlighted in the article that I need two tools to do my development: an editor and version control. You use these tools every day--EVERY day. There's no excuse for not knowing them intimately. They are the foundation for doing your job.

GUIs also aren't always available across platforms, either. For the most part, all the git CLI commands port from Mac, Linux and Windows (msysgit). Also, have you ever tried using a GUI when SSH'd into a remote server in a pinch? You can't. And you'll really wish you invested the time to learn those underlying CLI commands.

Re:Git add -p: a powerful git feature by rogerbinns on Monday November 05, 2012 @04:53PM (#4745998)
Do remember that half of all developers are below average/median for the relevant group. (See also "perpetual intermediates".)

My experience has been in forcing developers to use guis to do commits. It significantly improved their commits because they would browse over the changeset, could commit only specific hunks, didn't accidentally include extra gunk like test files, and generally made better messages.

It is certainly the case that the cli tools give experts the most power. But that power doesn't need to be exercised by everyone, and not even by experts on every occasion.

I would much rather my developer's heads are full of things relevant to the problem being solved (which is what pays the bills) than intricacies of cli tools.

Re:Git add -p: a powerful git feature by Evbn on Tuesday November 06, 2012 @12:15PM (#4749351)
What does a graphical diff and GUI message editor with interactive changelist management have to do with being "below median"? I came to write code, not restart my workflow from scratch every time I want to slightly edit my change.
Re:Git add -p: a powerful git feature by rogerbinns on Tuesday November 06, 2012 @04:32PM (#4750901)
Because everyone thinks of themselves as being above median, and a wiz at the tools. They know all the flags, workflows etc memorized and think everyone should be like them.

Whilst in the real world the other half do things like 'git commit -a' to make commits which likely picks up unwanted gunk. A gui does not require memorizing flags and makes everything plain.

Re:Git add -p: a powerful git feature by to3m on Monday November 05, 2012 @06:09PM (#4746325)
I think denying beginners the GUI is particularly cruel. The command line is much more of an abstraction in this case, I think! - gitk displays the actual tree of this graph that git manipulates, but the command line just prints text ;) It's especially illuminating (or I found it so, anyway) to keep gitk --all open as you do merges, rebases, pushes, fetches, etc., refreshing the display after each operation - it makes it very clear what's actually happening. I found git a bit of a mystery until I realised I could see what it was doing this way, and suddenly everything became clear.

Or maybe that's just me. I don't claim to be the sharpest tool in the box.

But anyway, you need have no fear that people won't get forced into using the command line eventually, just because they like git gui. Any time you want to do anything remotely complicated, you need to drop out of git gui and hit the command line. gitk, for all its ability to display the history in a useful format, is similarly limited (or designed for a specific purpose, if you prefer).

I really didn't get on with GitX, but I don't remember it being a great deal more than git gui and gitk, in the same app, with a fancy OS X-looking interface. So the same would probably apply.

Re:Git add -p: a powerful git feature by qu4z-2 on Tuesday November 06, 2012 @12:04AM (#4747306)
Both gitk and the cli are representations of the graph. Granted, gitk may be a more useful/comprehensive overview than say git log but still.
Re:Git add -p: a powerful git feature by w0utert on Tuesday November 06, 2012 @04:34AM (#4747756)
In general I agree. In the case of git, I disagree. The git CLI is downright terrible and dangerous to use unless you're already a git pro, I would never ever force a git newbie to stick with the CLI instead of using a GUI like SourceTree (which is fantastic).

I've used CVS, Subversion and Mercurial in the past and never needed or wanted a GUI, but with git, I don't even want to be bothered by all the inane commands and switches. I love git for all it does, but I despise the CLI because it simply is downright evil: inconsistent, incoherent, convoluted, allows you to shoot yourself in the foot in too many ways, terrible user messages, and so on.

Re:Git add -p: a powerful git feature by danieldk on Tuesday November 06, 2012 @09:27AM (#4748481)
The git CLI is downright terrible and dangerous to use unless you're already a git pro,

The Unix CLI is far more dangerous than Git. Also, there not very much you can do really wrong if you regularly push to a remote repository, as long as you don't push with force.

And don't we all do backups anyway?

Re:Git add -p: a powerful git feature by w0utert on Tuesday November 06, 2012 @09:58AM (#4748633)
>> The Unix CLI is far more dangerous than Git. Also, there not very much you can do really wrong if you regularly push to a remote repository, as long as you don't push with force.

Sure, but that's not really an excuse for git to have such a confusing and possibly destructive command line. I'm not a GUI person at all, but the times I had to lookup 20 different ways that 'git reset' worked, or had to google what on earth the apparently random combination of words like refspec, remote, origin, branch and non-bare actually meaned have been enough to drive me to a GUI tool. Now I'm much happier and actually enjoy working with git. Obviously when you are only pulling and pushing from master, there's not much that can go wrong, but if that's all you do, Subversion would do the trick just as well. The CLI usability completely falls apart when you start rebasing, merging and cleaning up WIP commits.

A tool like Mercurial proves that DVCS systems do not have to have a confusing CLI, in all the years I've been using it, I've never felt compelled to use a GUI. Too bad the Mercurial back-end is so slow.

Re:Git add -p: a powerful git feature by Evbn on Tuesday November 06, 2012 @12:12PM (#4749335)
3 comments up I predicted 'reset' would make an appearance. What is the point of having multiple command names if the command name says nothing about its behavior, and the command flags trigger completely diverse functionalities? Just have the CLI be git -a to git -zz and stop teasing users.
Re:Git add -p: a powerful git feature by masklinn on Tuesday November 06, 2012 @11:13AM (#4749011)
> The Unix CLI is far more dangerous than Git.

Not necessarily: the Unix CLI has more powerful ways to saw off your leg, but it won't saw off your leg by accident, it won't destroy your files because you passed a strange flag to `ls`.

Re:Git add -p: a powerful git feature by daveungerer on Monday November 05, 2012 @05:04PM (#4746058)
Mostly in agreement, I never said one shouldn't learn the git CLI and the fundamental concepts - I did that myself. But once you've mastered that, you're ready to move on to something that speeds up your day to day work.

Needing to use git now and then while SSH'd in is not a good reason to make your entire development process slower and more error-prone. I would also say that there is a larger problem with your process if you have the need to use git on "a remote server in a pinch".

It's kind of like learning to play a musical instrument. You absolutely must pay attention to the fundamentals as a beginner, but if you only ever work on the fundamentals you will never become a great musician.

Re:Git add -p: a powerful git feature by zem on Monday November 05, 2012 @05:16PM (#4746106)
this is one of the cases where the gui [i like git-cola personally] is definitely a better way to do things. if you complain that it won't work "in a pinch", you're optimising for the uncommon case. yes, it's useful to know how to do it from the command line, but for day-to-day use i find the gui more efficient.
Re:Git add -p: a powerful git feature by olalonde on Monday November 05, 2012 @07:36PM (#4746617)
I feel GUIs can be great learning tools to become better with the CLI. I've personally learned a lot of tricks and commands using a GUI Git client.
Re:Git add -p: a powerful git feature by yuvadam on Monday November 05, 2012 @05:09PM (#4746080)
Save time with a GUI? Seriously???

Keyboard strokes are, by any definition, much faster than mouse pointing-and-clicking. I have yet to find a single GUI that gets stuff done faster than what I can achieve with a command line prompt.

Re:Git add -p: a powerful git feature by daveungerer on Monday November 05, 2012 @05:32PM (#4746179)
How about staging 8 files out of 10 that are currently modified, with no matching glob patterns for the CLI to use? I don't care how fast your keyboarding is, simply selecting the 8 (even better, select all and unselect the 2 you don't want) and dragging them into the index is the fastest way.

Or how about firstly determining which old commit you would like to revert a single file to, then secondly doing the actual revert. I can just view the file's log at a glance, get the revision I want, right-click and select "Reset File to This Commit".

By the way, I love Vim. But your disdain for "pointing-and-clicking" sounds like so much machismo.

Re:Git add -p: a powerful git feature by motti on Monday November 05, 2012 @06:24PM (#4746401)
git add -i
Re:Git add -p: a powerful git feature by tesmar2 on Tuesday November 06, 2012 @06:42AM (#4747956)
Great tip, didn't know that!
Re:Git add -p: a powerful git feature by goldfeld on Tuesday November 06, 2012 @10:24AM (#4748752)
Some people literally actually don't have a mouse. It gets that good.
Re:Git add -p: a powerful git feature by to3m on Tuesday November 06, 2012 @11:24AM (#4749078)
These people can use the keyboard - git has comprehensive command line support, even if it isn't always as quick as git gui.
Re:Git add -p: a powerful git feature by Evbn on Tuesday November 06, 2012 @12:19PM (#4749375)
They day I learned that gvim has support for mouse hover tooltips, was a great day.
Re:Git add -p: a powerful git feature by mnutt on Monday November 05, 2012 @05:38PM (#4746201)
I can't imagine myself using a GUI for git, but there are some things that are faster with a GUI and mouse than with a keyboard. Almost all of them involve some kind of visual feedback. For instance, lately I've been working on some projects that involve absolutely positioning HTML elements on the page. This is a huge pain using a text editor--you make an estimate, save it, reload the page, see how it looks, and repeat. Just clicking and dragging is much, much easier.

Other than that, I generally think that keyboard is a faster input, though an 80-character terminal window is often a poor choice for visual feedback. Termkit has some interesting ideas: http://acko.net/blog/on-termkit/

Re:Git add -p: a powerful git feature by bowmessage on Monday November 05, 2012 @05:42PM (#4746219)
For the future, mnutt: I love Chrome's developer tools, you can directly edit CSS rules from the browser by right clicking on it and selecting inspect element. Helps a lot with these situations!
Re:Git add -p: a powerful git feature by recursive on Monday November 05, 2012 @06:00PM (#4746286)
And it's a gui!
Re:Git add -p: a powerful git feature by Evbn on Tuesday November 06, 2012 @12:18PM (#4749371)
TermKit author got mad at the community last year and went underground. :-( No idea if it will ever launch.
Re:Git add -p: a powerful git feature by mitchty on Monday November 05, 2012 @05:38PM (#4746200)
Yes, I use magit to stage chunks in emacs. Even if I have modified a file and end up staging the whole thing, looking at what i'm staging is way more useful than the way stock git presents things.
Re:Git add -p: a powerful git feature by jules on Tuesday November 06, 2012 @06:13AM (#4747903)
Your working speed is limited by typing or clicking? Mine is limited not by the speed I output information, but by the speed I get input. GUIs excel at that. A graphical view of source history is much better than what you get from the CLI, which is like living life while looking through a straw.
Re:Git add -p: a powerful git feature by tomlu on Monday November 05, 2012 @07:14PM (#4746556)
SourceTree is really cool but IME it's best for beginners to start with the command line. I've taught git to quite a few people now and see a correlation between early command line usage and understanding what is going on.

Once you're at the level of git add -p you can probably start thinking about using a GUI if that's your cup of tea.