Git

Merge & Rebase

Merge

  • Merging is nice because it’s a non-destructive operation. The existing branches are not changed in any way.

Rebase

  • Rebase moves all of the commits in feature on top of main, it changes the commit history of feature to make the history more clean

  • Make sure the feature is only for your use, since branch’s history has diverged from everybody else’s.

  • After rebased , force push is needed in order to rewrite the history

Sub Module

Create SubModule

Update SubModule

Existing SubModule Initialization

Delete SubModule

Fork

  • Firstly, it can make a copy of project to your repo through forking

  • Then, clone the code on local

  • After that, execute the following commands to update the code from source if needed

Reset

  • To cancel the committed change and reset the head

Hard

  • Discard all the committed changes and staged/ unstaged changes

Mixed

  • Put back your committed changes and staged changes into unstaged changes

Soft

  • Only put back your commited changes into unstaged changes

Tracing

Diff

  • To compare the change of file

Log

  • To get the commit history of file

Blame

  • To get file change and each commit line by line

Grep

  • To search the file based on keyword

Reflog

  • To record all your operations on local, including changing branch

  • If you want to recover some of operated changes, such as reset change, deleted branch change

  • You can checkout based on the history

Revert & Cherry pick

  • Cherry pick and revert can both select the commit of content from other branch into current branch

  • But revert is to select the opposite version of the commit

Git Hook

  • Hooks can reside in either local or server-side repositories, and they are only executed in response to actions in that repository. Here is the list of action:

  • pre-commit

  • prepare-commit-msg

  • commit-msg

  • post-commit

  • post-checkout

  • pre-rebase

References

Last updated

Was this helpful?