1. 將暫存的分支合併回來,不要有線圖
$ git checkout <你要開發的 branch>
$ git merge --squash <你要合併進來的 branch>
$ git branch -D <你要合併進來的 branch>

2. 建立一個 branch 並馬上切換過去
$ git checkout -b <branch name>

3. 刪除遠端的 branch
$ git push origin :<branch name>

4. 還原異動 (revert)
$ git reset --hard HEAD

5. 取消 commit (僅建議對未 push 的 commit 下)
$ git reset --soft HEAD^

6. git 更改遠端資訊
$ git remote -v
$ git remote rm origin
$ git remote add origin git@git-server:project_name
$ git push origin master

7. 修改本地 branch 名稱
$ git branch -m <new_branch_name>

8. 暫存區
目前異動存入暫存區
$ git stash
$ git stash save "WIP: stash_description"

列出所有暫存
$ git stash list

取出異動
$ git stash pop (取出異動但不移除 stash)
$ git stash pop stash@{0}
$ git stash apply (取出異動並移除 stash)
$ git stash apply stash@{0}

9. 只 merge 別的 Branch 的某個 Commit
$ git cherry-pick {commit token}

10. 使用 TAG
建立 TAG
$ git tag -a {tag_name} -m {msg}

push 某個 TAG 到遠端
$ git push orogin {tag_name}

push 所有 TAG 到遠端
$ git push origin --tags

11. 忽略 Linux 底下的檔案權限變動
$ git config core.fileMode false

12. 如果本機和遠端的 branch 清單不一置的時候,下這個指令同步一下
$ git remote update origin --prune

13. 強制更新本機版本與遠端一致
$ git fetch --all
$ git reset --hard origin/master

14. 比對本機與遠端的差異
$ git diff origin/master master

15. 取得目前 commit 的 hash
$ git rev-parse  HEAD
$ git rev-parse --short HEAD

16. 刪除所有本機的 branch
$ git branch -D `git branch --merged | grep -v \* | xargs`

17. 取得自動切換換行符號的設定
$ git config core.autocrlf false

18. 取得兩個 commit 之間的 log
取目前版號

$ git rev-parse --short HEAD

取兩版本之間 log
$ git log 797e51f..28aea6c

取兩版本之間的 diff
$ git diff 797e51f..28aea6c

19. 區分檔案大小寫
$ git config core.ignorecase false

20. 寫 merge 訊息時,使用 vim
git config --global core.editor "vim"

arrow
arrow
    全站熱搜

    wbkuo 發表在 痞客邦 留言(0) 人氣()