Today I Learned

2 posts by jasonyuen

Running past commands from history

There are many ways to search/recall previous commands from the command line but I find the combination of history and !<history_id> to be quite useful, especially when you don't remember the command you ran. For example:

Show me my previous commands:

> history
  513  git stash pop
  514  rspec spec/some_spec.rb
  517  git diff
  518  git add -p

Re-run the spec command in 514

> !514

Selectively stashing your changes

git stash -p will allow you to interactively stash changes at a patch level (like other git commands that support the -p option)