News for hackers. Stuff that matters.
Re:Gitjk – command to undo what you just did in git by _kst_ on Monday May 26, 2014 @04:25PM (#7801439)
If you name it "git-jk" rather than "gitjk", you can invoke it as

  git jk
Re:Gitjk – command to undo what you just did in git by bodyfour on Monday May 26, 2014 @06:34PM (#7801958)
The gitjk command needs to operate as a shell alias though
Re:Gitjk – command to undo what you just did in git by couchand on Monday May 26, 2014 @04:42PM (#7801537)
Is that specific to git or is it in the shell?
Re:Gitjk – command to undo what you just did in git by pyre on Monday May 26, 2014 @05:05PM (#7801626)
All of the:

  git <command>
commands are executables of the form 'git-<command>' in specific directory:

  $ git --exec-path
  /usr/local/Cellar/git/1.9.0/libexec/git-core 

  $ ls $(git --exec-path) | head
  git
  git-add
  git-add--interactive
  git-am
  git-annotate
  git-apply
  git-archimport
  git-archive
  git-bisect
  git-bisect--helper
In git's earlier years, it was just a set of git-<command> commands in $PATH, until the master git command was created (to 'rule them all' if you will).

git will actually pick up anything in $PATH of the form 'git-<command>' and allow you to run it as 'git <command>'. The downside of this, is that commands of the form:

  git <command> --help
are intercepted by git and converted to:

  man git-<command>
So your command cannot process the --help option itself when called like this (or it used to be this way a couple of years ago).

Edit: Another downside, is that some 'smart' command-line completion settings either have a hard-coded list of 'git <command>' commands, or look for said commands in the value returned by 'git --exec-path'. So you can't tab-complete git-<command> commands that you just drop into $PATH (at least not out of the box).

Re:Gitjk – command to undo what you just did in git by taejo on Monday May 26, 2014 @04:55PM (#7801590)
It is specific to git.
Re:Gitjk – command to undo what you just did in git by kolev on Monday May 26, 2014 @06:45PM (#7801996)
Git.
Re:Gitjk – command to undo what you just did in git by jamesgeck0 on Monday May 26, 2014 @04:24PM (#7801429)
I occasionally wish git had an undo-whatever-I-just-did command, and I've been using it for years.

The git fixup page comes in quite handy. https://sethrobertson.github.io/GitFixUm/fixup.html

Re:Gitjk – command to undo what you just did in git by tetha on Monday May 26, 2014 @04:06PM (#7801349)
Why is sudo hardcoded into so many commands? I'll run your program with privileges if it needs and earned them, thank you very much.
Re:Gitjk – command to undo what you just did in git by mapmeld on Monday May 26, 2014 @04:14PM (#7801379)
It will print (not run) the command unless you type 'gitjk -f'

When I run 'rm -r' on my machine it warns me about every file in the .git directory.

Re:Gitjk – command to undo what you just did in git by coherentpony on Monday May 26, 2014 @04:38PM (#7801499)
`sudo` is not the best practice with regard to removing that warning, try the `-f` flag instead.
Re:Gitjk – command to undo what you just did in git by tetha on Monday May 26, 2014 @04:53PM (#7801584)
I like how tame and polite your reply is.
Re:Gitjk – command to undo what you just did in git by coherentpony on Monday May 26, 2014 @06:13PM (#7801902)
Some days are worse than others. Some days I rage out. Other days I realise that some people just don't know something and the best practice is just to educate them rather than raise your blood pressure.

It really depends on how much coffee and sleep I've had. Thanks for the kind words.

Re:Gitjk – command to undo what you just did in git by mapmeld on Monday May 26, 2014 @05:06PM (#7801627)
Thanks! I've amended this in the current version
Re:Gitjk – command to undo what you just did in git by eertami on Monday May 26, 2014 @04:16PM (#7801394)
rm -rf?
Re:Gitjk – command to undo what you just did in git by bilalq on Monday May 26, 2014 @04:22PM (#7801425)
It's kind of nice that this just gives suggestions by default rather than running potentially breaking commands.

But as someone else here mentioned, you really want to understand the reflog in git. Everyone screws up at some point or another, and it's much easier to work through things when you can rely on the reflog to act as a safety net and an anchor of sanity.

Re:Gitjk – command to undo what you just did in git by pathikrit on Tuesday May 27, 2014 @02:27PM (#7806006)
Re:Gitjk – command to undo what you just did in git by prezjordan on Monday May 26, 2014 @04:43PM (#7801541)
The git reflog gets you out of all kinds of messes. https://medium.com/git-tips/a4189dd88c40
Re:Gitjk – command to undo what you just did in git by tjdetwiler on Monday May 26, 2014 @06:10PM (#7801895)
I'm pretty sure your fetch logic is not right. First it assumes no arguments are passed. You assume origin/master (which is convention but not guaranteed) and also you assume a refspec isn't passed (in which case you need to rollback FETCH_HEAD).
Re:Gitjk – command to undo what you just did in git by junkblocker on Monday May 26, 2014 @10:03PM (#7802507)
Re:Gitjk – command to undo what you just did in git by lunixbochs on Monday May 26, 2014 @04:30PM (#7801465)
If anyone wants a fish function:

    function jk
        history | head -n+10 | tail -r | gitjk_cmd
    end
Maybe git full undo via automatic snapshotting (branch/stash)? It's fine unless you hit a perf wall on huge repos.
Re:Gitjk – command to undo what you just did in git by thrush on Monday May 26, 2014 @06:09PM (#7801894)
Does it work if you call it 2x or more?
Re:Gitjk – command to undo what you just did in git by burke on Monday May 26, 2014 @05:30PM (#7801719)
rebase isn't very hard to implement; you just have to check the reflog.
Re:Gitjk – command to undo what you just did in git by homulilly on Monday May 26, 2014 @04:14PM (#7801381)
Uh... if you want to undo a git add shouldn't you be doing git reset?
Re:Gitjk – command to undo what you just did in git by mapmeld on Monday May 26, 2014 @04:21PM (#7801422)
somehow when I was testing it, I thought I needed to use rm -r --cached to remove a previously untracked file. It should do git reset in most cases.

Edit: now recommends git reset unless you did "git add ." or something like that.

Re:Gitjk – command to undo what you just did in git by achal on Monday May 26, 2014 @05:58PM (#7801851)
You may have been on your initial commit; in that case, you need to use rm --cached instead of reset to undo a git add.
Re:Gitjk – command to undo what you just did in git by svckr on Monday May 26, 2014 @04:01PM (#7801324)
Isn't that what git reflog + reset are for?
Re:Gitjk – command to undo what you just did in git by develop7 on Monday May 26, 2014 @04:15PM (#7801390)
It does rely on history? Well, it won't work for me then — in my history there's only frequently-used commands.
Re:Gitjk – command to undo what you just did in git by lazzlazzlazz on Monday May 26, 2014 @04:13PM (#7801376)
sudo hard-coded, and an intolerably stupid name. Next.
Re:Gitjk – command to undo what you just did in git by develop7 on Monday May 26, 2014 @04:17PM (#7801399)
well it could be named git-unfuck (1)
Re:Gitjk – command to undo what you just did in git by homulilly on Monday May 26, 2014 @04:19PM (#7801410)
Except going by the examples it actually just makes things worse by providing bad advice.
Re:Gitjk – command to undo what you just did in git by jpatokal on Monday May 26, 2014 @07:22PM (#7802117)
Such as?