Main git commands
This is the list of most useful git commands.
Stage changes by hunk
Git will interactively let you add, skip, or split diff hunks.
$ git add -p
Where:
- y - stage this hunk
- n - do not stage this hunk
- q - quit; do not stage this hunk or any of the remaining ones
- a - stage this hunk and all later hunks in the file
- d - do not stage this hunk or any of the later hunks in the file
- g - select a hunk to go to
- / - search for a hunk matching the given regex
- j - leave this hunk undecided, see next undecided hunk
- J - leave this hunk undecided, see next hunk
- k - leave this hunk undecided, see previous undecided hunk
- K - leave this hunk undecided, see previous hunk
- s - split the current hunk into smaller hunks
- e - manually edit the current hunk
- ? - print help
Checkout to a certain tag
First check if the tag list is updated.
$ git tag --list
If the desired tag is not in the list, update the tag list
$ git fetch --all --tags --prune
And then, checkout the correct tag.
$ git checkout tags/<tag_name>
Waring: When you checkout a tag, the head of the repo is pointing to a uncertain location, so the commits could not have the desired effect.
If you whant to commit some changes, make sure you are in an active branch before the commit.