Skip to content

Instantly share code, notes, and snippets.

@coin8086
Last active October 31, 2019 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coin8086/e5b72edd1ca31ecd3e548dbd11ff8165 to your computer and use it in GitHub Desktop.
Save coin8086/e5b72edd1ca31ecd3e548dbd11ff8165 to your computer and use it in GitHub Desktop.
Git Notes

Git Notes

EOL

  1. Windows Git client sets core.ignorecase to true by default, you may need to disable it to detect server changes on file names. Check it by git config --get core.ignorecase, and set it by git config core.ignorecase false.
  2. Detect file EOL by git grep -I '^M'. It searches for a literal CR character in files.

Diff

  1. To git show more lines before and after the changed lines, use git show -U <NUM>.
  2. To git diff a file/dir between two commits, use git diff <first-commit> <second-commit> [--] <filepath>. Either commit can be omitted, in which case it's as if HEAD is used for that omitted commit.

Push

  • Push all branches: git push --all origin
  • Push all tags: git push --tags

Reset/Force Update a Branch

Reset/force update the local branch you're currently on(dropping any local changes including untracked files): git reset --hard <commit>. The commit can be either a history commit on the branch, or not.

Clean

  • Reset all files and directories to HEAD and remove all untracked ones: git clean -xdf
  • Reset all files and directories to HEAD but do not remove any untracked one: git clean -Xdf

Patch

  • Patch commits since a commit(exclued) to the HEAD into one file: git format-patch <commit> --stdout > <patch-file>

  • Apply a patch file: git am <patch-file>

    When there's a conflict in applying patch, do it like git am -3 <patch-file> to enable 3-way merge, much like resolving a merge conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment