summer course
contributed by <YW0330>
64-bit Git for Windows Setup.
$ git config --list
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
.git
資料夾,儲存 Local repository 的所有資料,包含修改紀錄Git Bash Here
cmd
,linux系統直接使用 Terminal
。
$ git clone <url>
clone
。
$ git clone <url> <desired repository name>
$ git clone
時,注意不要使用 Ctrl+V
來貼上文字,使用 Ctrl+V
貼上文字然後再右鍵按 paste
會造成以下 bug
Git fatal: protocol 'https' is not supported
解決方式: stackoverflow-Git fatal
Download ZIP
$ git init
.git
隱藏資料夾。$ git add <filename>
$ git add .
$ git status
$ git commit
$ git commit -a
這道命令,讓 Git 自動追蹤變更的檔案並提交。
$ git commit -m "<commit title>"
$ git commit --amend
git commit --amend
僅限於重新提交最新的 commit message,若要修改之前的 commit message,必須使用 git rebase -i HEAD~~<倒數第幾個提交的 commit>
。$ git rebase -i HEAD~10
pick
為 r
或 reword
,儲存檔案在 git-rebase-todo
,接著離開COMMIT_EDITMESG
,接著離開$ git push -f
Fix big number in driver
已經改成 Fix big number size and time in driver
$ git log
$ git log --oneline
$ git diff
$ git reset <filename>
$ git checkout -- <filename>
GitLens
, Git History
擴充插件初始化
。+
, -
號變更檔案狀態
Ctrl
+Enter
可以提交 commit$ git remote add <remote username> <url>
<remote username>
: origin
,clone 的預設名稱$ git push <remote username> <local branch>
<local branch>
: master
, main
$ git push
$ git pull <remote username> <local branch>
$ git push
fork
複製一份專案副本到你的 GitHub 帳號。fork
後),並且想要修改原本的合作專案,可以提交 pull request,但是提交前要先注意 fork
時候的版本跟原本專案的版本是否相同。fork
版本跟原本專案的版本相同
直接提交 pull request
出現下面的畫面,撰寫標題和描述然後點選 Create pull request
即可。
請注意此處標題須符合 commit message 的規範,因為原專案作者會使用你的標題去創造 commit。
fork
版本跟原本專案的版本不相同
$ git remote add upstream <原本專案網址>
git 本身即支援多個倉儲,而自己本身的默認倉儲的名稱為 origin。
$ git fetch upstream
$ git checkout -b <分支名稱> upstream/master
請注意此處也會在原本專案中創造分支,代表原本專案作者也看的到分支。
$ git checkout master
$ git log
切回原本分支和瀏覽並挑選要提交的 commit 可以用看 github 中 commit 取代。
$ git checkout <分支名稱>
$ git cherry-pick <commit ID>
$ git push origin <分支名稱>
參考資訊: 如何只提交/應用指定 commit
.gitignore
檔案
# 不要追蹤檔名為 .a 結尾的檔案
*.a
# 但是要追蹤 lib.a,即使上面已指定忽略所有的 .a 檔案
!lib.a
# 只忽略根目錄下的 TODO 檔案,不包含子目錄下的 TODO
/TODO
# 忽略 build/ 目錄下所有檔案
build/
# 忽略 doc/notes.txt,但不包含 doc/server/arch.txt
doc/*.txt
# 忽略所有在 doc/ 目錄底下的 .pdf 檔案
doc/**/*.pdf