Skip to content

Instantly share code, notes, and snippets.

@smagch
Last active December 27, 2015 11:39
Show Gist options
  • Select an option

  • Save smagch/7319595 to your computer and use it in GitHub Desktop.

Select an option

Save smagch/7319595 to your computer and use it in GitHub Desktop.
useful command for Git

Useful Git Commands

I'm going to hold a Git study session on November 14th. This gist is just a personal memo.

Commands

  • git diff --cached use this everytime before commiting in order to avoid tiny careless mistakes.
  • git diff --name-only | xargs grep 'word-you-want-to-search' grep "word-you-want-to-search" among changed files.
  • git log -10 --graph | less show quick history.
  • git stash and (git stash pop or git stash apply) you should use them to switch branches.
  • git rebase -i to edit history.

Exercises

  • See cached file and none-cached files using git reset <filename> and git add <filename>. Use git diff, git diff --cached and git status. When a staged file is deleted, its cache would be still there. Do rm <filename> without using git rm. And then do git reset HEAD <filename>. The file would go away.
  • Specifing a directory would point to all files in the directory. Use git add, git reset HEAD, git diff to see the effect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment