Table of Contents
- 基本
- fetch
- tag
- branch
- merge
- rebase
- remote
- stash
- reset
- 修改commit(包含合併、重排、拆分)
- 查看檔案各行最新commit
- 資料復原
- git執行在case insensitive系統下(ex: mac),要改變folder名稱的大小寫的話需要執行以下:
基本
上一版本:HEAD^, 上兩版本HEAD~2, 上三版本HEAD~3…etc
1 2 3 4
| git add [file] git add -A git commit -m [comment] git push
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| git diff git diff --cached git rm file git mv <file_name> <new_file_name> git commit --amend git reset HEAD <file> git checkout -- <file> git pull origin == git fetch + git merge git fetch origin master git push origin master git status git log git show <SHA-1> git reflog git log -g
|
fetch
1
| git fetch <remote> <rbranch>:<lbranch>
|
tag
1 2 3 4 5 6 7 8
| git tag -a v1.4 git show v1.4 git tag -a v1.2 9fceb02 git push origin v1.5 git push origin --tags git push origin --follow-tags git tag --delete v1.5 git push --delete origin v1.5
|
branch
1 2 3 4 5 6 7 8
| git branch testing git checkout testing create branch and checkout to it git checkout -b testing git branch -d testing git branch -D testing
|
merge
根據兩個branch最新commit物件與共同parent的commit物件合併後,再建立新commit物件
1 2 3
| git merge testing git mergetool
|
rebase
根據兩個branch共同parent的commit物件作patch,再將patch打在rebase對象的最新commit上
一旦分支中的提交物件發佈到公共倉庫,就千萬不要對該分支進行衍合操作
remote
1 2 3 4 5 6 7
| git remote add <name> https://xxxx/xxx.git git fetch origin git checkout -b develop origin/develop git push remote [master]:[master] git push origin --delete <branch_name>
|
stash
暫存所有未commit的變更至stash(is a stack)
在欲切換branch又不想commit時好用
1 2 3 4 5 6 7 8
| git stash git stash list git stash apply git stash drop git stash pop == apply + drop git stash show -p | git apply -R
|
reset
1 2 3 4 5 6 7
| git reset HEAD^ git reset --hard HEAD^ git reset --hard <SHA-1>
|
修改commit(包含合併、重排、拆分)
查看檔案各行最新commit
1
| git blame -C -L 141,153 GITPackUpload.m
|
資料復原
例如執行了這個:git reset –hard
事實上commit物件還在,只是沒有ref物件指向它而已
所以可以救
1 2 3 4 5 6 7
| git log -g git fsck --full git branch recover-branch <丟失的commit物件的SHA-1>
|
git執行在case insensitive系統下(ex: mac),要改變folder名稱的大小寫的話需要執行以下:
1 2 3
| git mv foo foo2 git mv foo2 FOO git commit -m "changed case of dir"
|