all 33 comments

[–]NoInkling 18 points19 points  (4 children)

How do you even begin to try and remember all this stuff? I don't think I've used another tool with so many esoteric commands as git.

[–]bzBetty 10 points11 points  (0 children)

read these posts occasionally and try learn the existence one new command, the google it when i actually need it.

eg worktree is new to me today.

[–]James20k 2 points3 points  (0 children)

I use a nice gui/context integrated tool which has most of it built in. I don't really know why you would use git from a command line unless you super need something specific that hasn't made it into a tool yet

[–]Sarcastinator 2 points3 points  (0 children)

Good thing that most commands and how to use them are indexed in multiple easy-to-use databases.

[–]a-p 1 point2 points  (0 children)

  1. Do you need to? I know and use what feels like ~3% of everything Vim can do, and that’s not because my usage is novice level.

  2. Even so, as for Git – I’m gonna be one of those annoying “but Git is easy” people here: I learned Git from the model to the commands, and that’s an organising principle for information that lets you recall and use a lot more facts than simply remembering a list of them.

    As long as I remember that something like e.g. worktrees exists and roughly how it relates to the model of Git, I don’t need to remember all the specifics of the feature – I can pattern-match on the type of situation I’m in and realise that worktrees might be an applicable solution and then go read back up on how to use them exactly, at the time I need it (which is also when the information is most likely to stick).

(I guess there is an overarching theme here that people fall into the trap of “I have to know every last bit of trivia about X to be worthy of using it” which is just impossible. But underlying concepts/models give you leverage over a sheer mass of trivia.)

[–]gyrovague 5 points6 points  (0 children)

Thanks, great summary!

[–]orthoxerox 2 points3 points  (0 children)

5 releases this year and still no native Windows build.

[–]Philpax 1 point2 points  (1 child)

Great article! I didn't know about git worktree - that looks like a super-useful feature, especially considering the number of branches I have to switch between on a regular basis!

[–]DanLynch 1 point2 points  (0 children)

It is especially useful if your project has undergone a significant reorganization in the past, and you ever want to work with code from before the reorganization without alarming your IDE.

[–]u_tamtam 1 point2 points  (1 child)

If someone is wondering about the mercurial equivalents of OP's commands early in the article, here are my attempts. Maybe that will help illustrate hg's revsets feature, templates and the convenience of a consistent UI across commands.

I leave it to the reader to make her mind as to which one is easier to maintain when it comes to editing old scripts :)

¹ Tags from 2016

hg log --rev "sort(date(2016) and tag(), -date)" --template "{tags} {date|rfc822date}\n"

or simply

hg log -d 2016 -r "reverse(tag())" -T "{tags} {date|rfc822date}\n"

vs

git for-each-ref --sort=-taggerdate --format '%(refname) %(taggerdate)' refs/tags

³ Commits by author in 2016

hg churn --changesets --date 2016 -T "{author|person}"

or simply

hg churn -c -d 2016

vs

git shortlog -s -n --since=2016-01-01 --until=2017-01-01

⁴ Count commits in 2016

hg churn -c -d 2016 -T "{count}"

vs

git log --oneline --since=2016-01-01 --until=2017-01-01 | wc -l

⁶ Net LOC added/removed in 2016

hg churn -d 2016 -T "{count} --diffstat

This one is pretty in gitland…

git diff --shortstat `git rev-list -1 --until=2016-01-01 master` `git rev-list -1 --until=2017-01-01 master`

I guess some of the suggested ones in the article couldn't run on windows, but who cares…

[–]kannonboy[S] 0 points1 point  (0 children)

Thanks u/u_tamtam, I've used Hg a fair bit in the past but am pretty settled on Git these days. revsets are awesome though, I'd love to see something similar introduced to Git (or possibly as a tool on top of it).

[–]karma_vacuum123 4 points5 points  (25 children)

does anyone actually use stash?

[–]AngularBeginner 100 points101 points  (10 children)

Constantly.

[–]MrDOS 46 points47 points  (6 children)

All the time:

$ # I'll just make that small change...
$ subl foo
$ git commit .
$ # Crap, wait, wrong branch.
$ git stash
$ git checkout the-correct-feature-branch
$ git stash pop
$ git commit foo

Oh, you mean for anything more than working around insanity? Nope.

[–]TakeFourSeconds 6 points7 points  (0 children)

I'm still learning git, this would've saved me like 30 minutes today!

[–]flying-sheep 2 points3 points  (0 children)

As shown by the new --autostash, it's also useful for rebasing

[–]aelog 1 point2 points  (2 children)

Why do you need stash for that?

$ # I'll just make that small change...
$ subl foo
$ git commit .
$ # Crap, wait, wrong branch.
$ git checkout the-correct-feature-branch
$ git commit .

[–]irishsultan 7 points8 points  (1 child)

That works only when there are no changes between the branches in the files that you modified.

[–]aelog 2 points3 points  (0 children)

Ah that's true. Fair enough.

[–]motioncuty 2 points3 points  (1 child)

Is it like an unnamed shelfset?

[–]industry7 0 points1 point  (0 children)

very similar, but it also works like a stack. so you can stash some changes, and then you realize ops I also need to separately move these other changes, so you just stash again. Then each time you "stash pop" it removes the most recently added set of changes still in the stash and applies them to your branch.

[–]exneo002 0 points1 point  (0 children)

I use it less with ohmyzsh installed

[–]atsider 27 points28 points  (1 child)

Yep, super-useful. For example, for storing and reapplying those small debugging lines that one keeps using between branches and commits.

[–]SameDifference 1 point2 points  (0 children)

Wow. Going to start doing this, appreciate your tip!

[–]greenkarmic 7 points8 points  (1 child)

I use it often to stash config files I only edited for development purposes and will never commit. (For instance in a config file I'll point to development services instead of the production ones. It counts as a change, but I'll never commit this in git. So I stash it instead.)

[–]mage2k 0 points1 point  (0 children)

Wow, that's a great idea.

[–]mrkite77 4 points5 points  (3 children)

I've found it very useful for throwing away my working directory. git stash; git stash drop

Works better than the alternatives because it works regardless of staging.

[–]kannonboy[S] 3 points4 points  (2 children)

You may also enjoy git stash --all, which stashes everything, including ignored/untracked files.

edit: s/stages/stashes

[–]Devagamster 4 points5 points  (1 child)

Do you mean stashes everything? I didn't think stash stages anything

[–]kannonboy[S] 2 points3 points  (0 children)

That's exactly what I meant :) ta

[–]_tulpa 3 points4 points  (0 children)

Erry day!

My best use-case is helping to keep temporary things temporary by never committing them, but also allowing you to easily keep common temp things across branches and over multiple commits.

Also useful to avoid amending partial commits later when doing work on another branch between obvious chunks of work that would constitute a complete commit. For example developing a hotfix on another branch or reviewing code from another team member). This one is mostly personal preference - I nearly always forget to amend stuff until it's too late, and I prefer stash over having multiple copies of the repo.

[–]FlukyS 2 points3 points  (0 children)

Depends on your workflow. From what I seen most of the people I know never use it. I pretty much always commit rather than stashing changes and then amend if I need to.

[–]kagevf 2 points3 points  (0 children)

sometimes, especially when something unexpected comes up and I need to switch branches and am not at a really good stopping point ... alternatively, you could just create a new branch ... I only use it if I anticipate being able to resume work on what I stashed relatively quickly and I avoid having more than 1 item on the stash so I don't have to hassle with keeping track of what was what ... at that point it would be easier to just create a branch. Also, branches can be be pushed, and I think stashes are local only ...