--- tags: Git --- # git 使用 ## 指令 ### git log --oneline --decorate --graph --all ### git config --list 列出使用者設定 ### git diff 比較檔案修改前後的變化 ### git add 將檔案由 working directory 加入 staging area ### git reset 將檔案由 staging area 撤回 ### git status 檢查 working directory 的狀態 ### git diff --cached 顯示 staging area 暫存的內容 (git add後使用) ### git commit 將所有 staging area 的內容提交為一個 commit ### git log 顯示所有在 local repository 的 commit 可以加上 --graph 的選項顯示 commit 之間連結的關係 ### git show 檢視某一個 commit ### git push 將 local repository 的 commit 上傳到共用的 remote repository ### git pull 將 remote repository 的 commit 下載到 local repository ### git checkout 將 working directory 的內容切換成某一個 commit / tag / branch 的狀態 ### git reset --soft 將 local repository 的 commit 撤回至 staging area。 > 使用這個指令時必須非常小心,如果撤回的對象並不是 HEAD,會造成其他 commit 遺失 ### git remote remove origin 刪除原本的 origin ### git push --set-upstream origin master 首次上傳,要先將本地分支註冊進 .git/config 內 ### git blame [filename] 列出每一行 code 是誰、什麼時候加進去的 ### 將檔案先暫時收起來,不 track git rm --cached ### 開 local branch 修 bug git checkout -b B#111 git checkout master (say fix in current branch.) git merge B#111 or git merge --squash B#111 git commit ### 新增檔案到最後一次 commit git add [file] git commit --amend --no-edit ### reset 後想救回檔案 git reflog (查看該 commit) git reset [SHA1] --hard ### 只想 commit code 部分區塊到 git 上 git add -p ### 在 git 中搬移檔案 git mv build/fileA legacy/fileA git ci -am'move file' git push git mv build/fileA legacy/fileA git pull //此時因為有local cache, git會自行判斷是否可繼續 git ci -am'move file' git push //此時因為diverge, push失敗. ### 刪除 git add 中某個 file git reset HEAD SynoBuildConf/install ### 找看看哪寫 remote branch 有此 commit git branch -r --contains \<commit\> ### 找看看 line 再哪寫 commit 有被更動 git log -c -S"line" ### fetch remote branch git fetch origin DSM6-2:DSM6-2 ### git rebase 用法整理 reword: 改 commit message ### git format & apply patch // 從某一個 commit 開始往後生成patch git format-patch <commit> git apply --check <patch> git apply <patch>