Begin to Learn Git

Commonly-used Git Commands

let current working directory to be called “cwd” for short

Basic

init
add

  • add <file>
  • add -p <file>: choose which change to commit
    commit: take a snapshot of the added files
    diff
  • diff <file>: compare <file> in cwd and file in HEAD
  • diff <branch/hash> <file>: compare <file> in cwd and file in <branch/hash>
  • diff <branch1/hash1> <branch2/hash2> <file>: compare <file> in <branch1> and <branch2>

Branch & Merge

branch

  • branch: look up all the branch infos
  • branch <branch>: create a new branch <branch>
    checkout
  • checkout <branch>
  • checkout <file>: copy <file> in HEAD to cwd, one way to throw away changes
  • checkout -b <branch>: same as branch <branch>; checkout <branch>
    merge
  • merge <branch>:
    • if HEAD is the ancestor of <branch>, then promote the HEAD->branch and merge with <branch>
    • else, a merge conflict occurs, and remains to by solved by the user
  • merge --continue: tell git the merge has finished]
  • merge --abort: come back to the state before you call merge

Remote

remote

  • remote add <remote> <URL>
    push
  • push <remote> <local branch>:<remote branch>
  • branch --set-upstream-to=<remote branch>
  • branch -vv
  • push
    clone
  • clone <URL>
  • clone --shalow: only clone the latest snapshot
    fetch
  • fetch <remote>
    pull
  • = fetch + merge
  • you can take it as updating the pointers in addition to the snapshots

Other

one of the key algorithm behind git is the Delta Compression Algorithm

  • blame
  • stash
    • stash pop
  • bisect: for debug
  • the .gitignore file: filenames and patterns that you want git to ignore

猜你喜欢

转载自blog.csdn.net/w112348/article/details/113006433