Live data from Hacker News

Lesser known Git commands

hackernoon.com

101–110 of 142 posts

Re: Lesser known Git commands

#101
post #16

I've seen more stash accidents than any other kind with git. Stashing is more dangerous than committing or branching, and to me it doesn't seem to provide any advantages... do people actually find stashing easier than branching? Is it just because when you branch you have to name it, and that causes friction? I stay away from stash. Right from the man page: "If you mistakenly drop or clear stashes, they cannot be rec…

I mostly only stash when I want to rebase -i because rebase -i seems to complain when I have uncommitted changes.

You might check out "git rebase --autostash" if you haven't already.

Re: Lesser known Git commands

#102
Some of my aliases, first some basic shortcuts:

  freshen = commit --amend --no-edit --date=now
  cont = rebase --continue
  br = branch --column
  recent = branch --sort=committerdate
  idiff = diff --cached
  ff = merge --ff-only
  co = checkout
Show what's left to do in an interactive rebase:

  todo = !cat `git rev-parse --git-dir`/rebase-merge/git-rebase-todo
Set tracking to to origin/

  upstream = !zsh -c 'git branch --set-upstream-to=origin/$(git symbolic-ref --short HEAD) $(git symbolic-ref --short HEAD)'
I use this to swap my work to home e-mail or vice-versa if I've got it wrong. Need to specify an initial commit.

  allmine = filter-branch --env-filter 'GIT_COMMITTER_EMAIL=my@email.com GIT_AUTHOR_EMAIL=my@email.com'

  vim = "!gvim `git ls-files -m`"

Re: Lesser known Git commands

#103
I'm still getting to know Git, and I appreciate articles like this as they touch on approaches to Git that have benefits in the real world, but I can't help but feel that version control tools should be simpler.

Does anyone have any experience with version control tools that have worked out simpler to use than Git? I've heard good things about Darcs before (aside from its performance issues, which projects like Pijul are designed to address), are there any other tools that are worth investigating?

Re: Lesser known Git commands

#104
post #6

My personal favorite two: jschroeder@omniscience:~$ git config alias.up pull --rebase jschroeder@omniscience:~$ git config alias.down push They can be used thusly: git up && git down

While these aliases are useful, I'm confused why "down" means "push".

Well git up is a literal translation of what svn up does. git down is just funny. Being a child of the early 80s, I guess it makes me think of this awful old school rap:

https://www.youtube.com/watch?v=OwU32Fa_Mko

Re: Lesser known Git commands

#105
post #16

I've seen more stash accidents than any other kind with git. Stashing is more dangerous than committing or branching, and to me it doesn't seem to provide any advantages... do people actually find stashing easier than branching? Is it just because when you branch you have to name it, and that causes friction? I stay away from stash. Right from the man page: "If you mistakenly drop or clear stashes, they cannot be rec…

> do people actually find stashing easier than branching?

Absolutely. I stash things all the time. I find feature branches only useful for pull requests. My own code never uses feature branches unless I'm unsure of where I'm headed with the feature—I'll need to continually come back to it and build it a little at a time. But that's very rare.

> Right from the man page: "If you mistakenly drop or clear stashes, they cannot be recovered through the normal safety mechanisms."

Then don't ever use those commands. I don't. Checking one of my repos:

    $ git stash list | wc -l
          46
I just let the stash grow unbounded. Usually it's for cleaning up unfinished features or debugging when manipulating the repo (in which case it gets popped almost immediately). But often I'll just hit a point where I don't care about what I have too much, but I think it might have promise in the future and so I'll just stash and start over. One of the wonderful git commands is "git stash list -p", letting me search the diffs for code I know I've written at some point.

Re: Lesser known Git commands

#106
post #71
post #16

I've seen more stash accidents than any other kind with git. Stashing is more dangerous than committing or branching, and to me it doesn't seem to provide any advantages... do people actually find stashing easier than branching? Is it just because when you branch you have to name it, and that causes friction? I stay away from stash. Right from the man page: "If you mistakenly drop or clear stashes, they cannot be rec…

Why did you write your rearrange with the ! form? The whole point of the leading ! is to say "don't prefix my alias with `git`", but then you go ahead and prefix your alias with `git`. You should be able to write that as rearrange = "rebase -i $(git merge-base HEAD @{u})"

I was under the impression that you needed to use !-form if you wanted git to use the shell itself, and that not using it basically just does an exec on the subcommand? Is that inaccurate?

Re: Lesser known Git commands

#107
> git commend quietly tacks any staged files onto the last commit you created, re-using your existing commit message. So as long as you haven’t pushed yet, no-one will be the wiser.

Well, they might notice that the author and committer dates don't match, but you can add "--reset-author" to really make this undetectable.

Re: Lesser known Git commands

#108
post #16

I've seen more stash accidents than any other kind with git. Stashing is more dangerous than committing or branching, and to me it doesn't seem to provide any advantages... do people actually find stashing easier than branching? Is it just because when you branch you have to name it, and that causes friction? I stay away from stash. Right from the man page: "If you mistakenly drop or clear stashes, they cannot be rec…

yeah, I find myself more doing a local commit with message WIP. I switch branches to do something else, come back, look at the log and if WIP, roll back the last commit

Re: Lesser known Git commands

#109
post #106
post #71

Earlier quoted context omitted.

Why did you write your rearrange with the ! form? The whole point of the leading ! is to say "don't prefix my alias with `git`", but then you go ahead and prefix your alias with `git`. You should be able to write that as rearrange = "rebase -i $(git merge-base HEAD @{u})"

I was under the impression that you needed to use !-form if you wanted git to use the shell itself, and that not using it basically just does an exec on the subcommand? Is that inaccurate?

Hmm, maybe you're right. I don't know anymore. I thought it just prefixed aliases with "git " and otherwise ran them as normal, but I admit I haven't researched this topic in a long time.

Re: Lesser known Git commands

#110
post #16

I've seen more stash accidents than any other kind with git. Stashing is more dangerous than committing or branching, and to me it doesn't seem to provide any advantages... do people actually find stashing easier than branching? Is it just because when you branch you have to name it, and that causes friction? I stay away from stash. Right from the man page: "If you mistakenly drop or clear stashes, they cannot be rec…

In Chromium (well, actually depot_tools[1], the closest thing Chromium has to a developer SDK) we provide `git freeze`[2] and `git thaw`[3]. These behave similarly to 'stash', but instead of taking your content and putting it who-knows-where, they commit it on top of your current branch in a special FREEZE commit (or multiple commits, if you have both staged and unstaged changes) which they then know how to thaw out again. Our other tools (such as `git rebase-update`[4]) also know how to deal with FREEZE commits, and can automatically thaw them for you when you go back to working on that branch.

[1] https://chromium.googlesource.com/chromium/tools/depot_tools... [2] https://commondatastorage.googleapis.com/chrome-infra-docs/f... [3] https://commondatastorage.googleapis.com/chrome-infra-docs/f... [4] https://commondatastorage.googleapis.com/chrome-infra-docs/f...

Post reply on HN