- git status 這個指令可以讓你看清單
git diff這個指令讓你看看變更
- 但ㄟ為啥這樣做 gitignore 沒效果啦(補充 push -u 的意思)
# I have a very new GitHub Repository 'w' | |
git remote add origin https://github.com/x200706/GitTest.git | |
vi README.md | |
vi .gitignore | |
git init | |
git add README.md | |
git add .gitignore | |
git status # 單純看看 | |
git config --global user.email "chi200706@gmail.com" | |
git config --global user.name "Crystal" # reset 的話這個也會洗掉欸 | |
git commit -m "first commit~" | |
git branch -M main | |
git push -u origin main |
- 拆 commit
git log --oneline # 顯示已有 commit |
輸出
ae96660 (HEAD -> main, origin/main) first commit~
1b052d9 Initial commit
拆掉他!!
git reset ae96660^ | |
git status |
git reflog 可以讓你看到 commit 異動
reset 直接 push 不用 commit
喔喔 後來這樣 reset 剛好謎底揭曉了,是 replit 的 init commit 把那些我想 ignore 的檔案推上去 =_=
- 開分支
git branch test | |
git branch 顯示分支 |
輸出
* main
test
把東西加到新分支 合進 main 再推
git checkout test | |
# git add | |
git checkout main | |
git merge test | |
# merge 推上去需要 commit | |
# 因為剛剛 reset 過 重設了信箱跟姓名 | |
git commit -m "merge test" | |
git log --oneline | |
git push -u origin main |
順便推推看另個分支
git log --oneline | |
git checkout | |
git status # 嗯 我的東西呢 'w'??????????????? |
嗯 'w'???????????????
reflog 用於除錯
git reflog |
輸出
3f0dd89 (HEAD -> main, origin/main) HEAD@{0}: checkout: moving from test to main
1b052d9 (test) HEAD@{1}: checkout: moving from main to test
3f0dd89 (HEAD -> main, origin/main) HEAD@{2}: commit: merge test
1b052d9 (test) HEAD@{3}: checkout: moving from test to main
1b052d9 (test) HEAD@{4}: checkout: moving from main to test
1b052d9 (test) HEAD@{5}: reset: moving to ae96660^
ae96660 HEAD@{6}: Branch: renamed refs/heads/main to refs/heads/main
ae96660 HEAD@{8}: commit: first commit~
1b052d9 (test) HEAD@{9}: commit (initial): Initial commit
老鐵你根本沒 merge 啊
往上看歷程,是這邊(下方代碼第 7 行之前)出錯啦
git checkout test | |
# git add | |
# 這邊就應該 commit 才切 main 再 merge | |
git checkout main | |
git merge test | |
# merge 推上去需要 commit | |
# 因為剛剛 reset 過 重設了信箱跟姓名 | |
git commit -m "merge test" | |
git log --oneline | |
git push -u origin main |
刪掉 test 分支建另個吧 ==
git branch -d test | |
git branch | |
git branch test1 | |
git branch |
來把這個分支推到遠端
git checkout # 這樣可以看目前在哪裡 | |
vi test.md | |
git status | |
git commit -m "branch test" | |
git log | |
git push -u origin test1 |
這時候我去 GitHub 發現別的事情了 0.0
他說我的庫 main 沒被保護,另外就是 test1 這個 push 產生了一個請求
請求如果許可 他就會以獨立分支出現在 GitHub 上;許可後的請求如果同意它 merge 進 main,它就會進 main
至於分支保護是這回事
# 拉取 更新那些事情
git pull # 這樣會拉取當前分支的遠端內容窩 |
- fetch vs pull:CLI 的 git 根本沒有 update
Jetbrains 教壞系列- 高見龍也有解說
# What is HEAD?
- 【冷知識】HEAD 是什麼東西?
# reset vs revert
上方有個亮點,就是這兩個都要 push 才生效,但 commit 清單長度會不太一樣
效果也不一樣
# Git Tag 相關
git tag # 條列 tag | |
git tag test #建立 tag | |
git tag -d test #刪除 tag | |
# tag 推遠端 | |
git push origin --tags #推全部 tag | |
git push origin --tags test1 #推單個 tag |
How To Delete Local and Remote Tags on Git
