[v] Basic Git Branching & Merging

這是 Git 官方文檔,寫得非常簡明易懂
https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

Atlassian( 出品 GitBucket, JIRA 等服務的公司) 的文檔,也可以參考看看
https://www.atlassian.com/git/tutorials/using-branches


下面則是我過去做的一些簡單的 git 指令筆記


http://gogojimmy.net/2012/02/29/git-scenario/

$ git checkout -b new-branch `git rev-list --max-parents=0 HEAD`

切回第一個 commit,再開一個新的 branch (new-branch)

$ git checkout branch-1
切換到叫做 branch-1 的 branch

$ git branch -D branch-2
在其他 branch 砍掉一個叫做 branch-2 的 branch
http://stackoverflow.com/questions/2003505/delete-a-git-branch-both-locally-and-remotely

$ git log
進入commit清單,每個commit後面有獨一無二的commit hash key, 按 q 跳出。

$ git reset --hard <commit hash key>
回到指定的 git commit, 並讓你的 local code 和 local history 跟那個 commit 一模一樣...

如果要避免下面的問題

“It will make your local code and local history be just like it was at that commit. But then if you wanted to push this to someone else who has the new history, it would fail.”

我們可以用...
$ git reset --soft <commit hash key>

"It will make your local files changed to be like they were then, but leave your history etc. the same."

http://stackoverflow.com/questions/3639115/reverting-to-a-specific-commit-based-on-commit-id-with-git

$ git checkout <commit hash key>
只是要切回過去某個 commit, 之後還要切回來...

http://stackoverflow.com/questions/4114095/revert-git-repo-to-a-previous-commit

在 github 上設 repo 後,在 terminal 中輸入 $ git clone [git repo網址],就可以把 github repo 傳回 local, 兩邊的 repo 從此連在一起。

local repo 要換位置的話,直接 ctrl-x/ctrl-v 貼到目標檔案夾即可。原因是該 local repo 中有隱藏檔 .git 標示連接的 git repo

要 undo git add 就用 git reset