]> rtime.felk.cvut.cz Git - hubacji1/oneflow.git/blobdiff - branching.md
Add coffe
[hubacji1/oneflow.git] / branching.md
index 3806a5079db91abf4f58cb674ac48ecf891a872c..d83b6d13c1f606ccd5c5ef183fa3359a886d234e 100644 (file)
@@ -2,20 +2,37 @@
 It's not a good idea to multitask when working. However, some projects just
 need it. The reason can be multiple features you are developing in parallel or
 more than one guy working on the project. To keep track of different changes
-that are realated the concept of branches was introduced.
+that are related, the concept of branches was introduced.
 
 Branch is just alternative history that can be merged one day back to the main
 history. The main history branch is named `master` by default.
 
+# Checkout and reset to history
+NOTE: Commit all the changes before playing around with git history. It means
+that `git status` says *nothing to commit, working tree clean*.
+
+`git checkout COMMIT_ID` changes *HEAD* (where we are in git history right now)
+to some commit. Working tree is still clean.
+
+`git reset COMMIT_ID` again changes *HEAD* to some commit. However, it also put
+all the affected *patches* (patches that was commited after) to working
+directory (not staged, nor in git history).
+
+`git reset --hard COMMIT_ID` do the same as `git reset COMMIT_ID` except it
+*deletes all the affected patches*.
+
 # Explore branches
 `git branch` command show all the local branches and the active branch you are
 currently on. Show remote branches by `git branch --all` command.
 
+For `git log` command, add `--branches` or `--all` parameters:
+
+`git log --oneline --graph --decorate --all`
+
 # Create and switch branches
 When decided to create new branch `git branch NAME` can be used. The branch
 will be created from the current state called *HEAD*. Switching between
-branches is done by `git checkout NAME` command. Checkout to specific commit is
-also possible by `git checkout COMMIT_ID`.
+branches is done by `git checkout NAME` command.
 
 If branch creation from specified commit is prefered, use `git branch NAME
 COMMIT_ID`.
@@ -33,15 +50,21 @@ COMMIT_ID` takes current branch and put it on top of the `COMMIT_ID`. Also,
 `git rebase NAME` could be used for rebasing current branch on top of other.
 
 # Cheat sheet
+## Checkout and reset
+- `git checkout COMMIT_ID`
+- `git reset COMMIT_ID`
+- `git reset --hard COMMIT_ID`
+
 ## Explore
 - `git branch`
 - `git branch --all`
+- `git log --oneline --graph --decorate --branches`
+- `git log --oneline --graph --decorate --all`
 
 ## Create
 - `git branch NAME`
 - `git branch NAME COMMIT_ID`
 - `git checkout NAME`
-- `git checkout COMMIT_ID`
 
 ## Merge
 - `git merge --no-ff NAME`