# Git Note ###### tags: `Git` 分散式的版本控制系統 分散式:相對於集中式,每個人手上都有足夠正確的資料可以將資訊拼湊出來 ```bash $ git config --list $ git config --global user.name "yourName" $ git config --global user.email "yourEmail@gmail.com" $ ctrl+w = 砍 word $ ctrl+u = 砍整排 $ ctrl+r = 搜尋歷史紀錄 $ ctrl+l = 清畫面 上、下 按鍵 按q 結束瀏覽 $ git init #初始化Git專案 $ git status $ git add <檔案>... #暫存 $ git add . #暫存全部 $ git rm --cached <檔案>... #取消暫存 $ git restore --staged <檔案>... #捨棄工作區的改動 $ git commit -m "commit的訊息" $ git log #view history $ git log --oneline #view history in one line $ git checkout <至少4個字的ID> $ git checkout master ``` ## Visual Studio Code ### 擴充套件(Extensions) * Git Graph ```bash #情境一:救檔案 #.git是儲存紀錄的地方,千萬不要亂刪 $ git restore <file> <file> #取消工作區檔案的改動 $ git restore . #取消工作區所有改動(別亂用) $ git restore --staged <file>#取消暫存區改動(從暫存區拉回到工作區) #情境二:這段程式碼是誰寫的? $ git blame <file> $ git blame -L 1,100 <file> $ git help <指令> #分支:像貼紙一樣 #commit時,HEAD會帶著所在的branch往前走 $ git branch #檢視有哪些分支 $ git branch <branch> #新增分支 $ git branch -d <branch> #砍掉分支 $ git branch -D <branch> #砍掉分支(效力更高) $ git switch <branch> #切換分支 $ git branch -m <branch> #分支重新命名 #合併分支可以看成是在移動貼紙 $ git merge <branch>#合併分支,舊往新(fast-forward) $ git merge <branch> -m "..." #情境:合併時發生衝突 #合併、解衝突、修改、再次add commit # 合併的第二種方法 $ git rebase <branch> #合併、解衝突、修改、再次add、--continue $ git rebase --continue $ git reset --mixed <id> $ git reset --soft <id> $ git reset --hard <id> $ git reset HEAD\^ #退回到上一步 $ git reset HEAD\~4 #退回到前4步 $ git reflog #HEAD的移動記錄表 $ git reset ORIG_HEAD --hard #危險紀錄的reset ``` ```bash $ git remote add kitty git@.... 設定遠端節點kitty到git@... $ git push origin main 把本地main上傳到遠端origin ssh-keygem $ git cat-file ..-t/-p $ git rebase -i sha1 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up