--- tags: 前端工具 --- 【筆記】GIT === 📖 [參考-git Document](https://git-scm.com/docs) # 指令 📖 [參考-git情境劇](http://blog.gogojimmy.net/2012/02/29/git-scenario/) ### 常用情境 #### 1. 修改剛剛的commit ``` // 修改完資料後, 加到stage git add xxxx.xxx 或 git add . // 不要編輯commit message git commit --amend --no-edit ``` ``` // 修改剛剛的commit message git commit --amend -m 'xxxxxxxxxx' ``` #### 2. 取消修改 ``` git reset HEAD^ ``` ``` git reset HEAD~1 ``` #### 3. 合併多個commit ``` git rebase -i HEAD~4 ``` > 另一方式:git graph的方式 - 在前一個commit上按右鍵,點選「Rebase current branch on this commit...」 #### 4. 合併分支 ``` git rebase 分支名(接到此分支名之後) ``` #### 5. tag - 上tag ``` git tag tag名 commit名 ``` - list tag ``` git tag --list 'feature*' ``` - 刪tag by patterns ``` <!-- local --> git tag -d $(git tag -l "*") <!-- 遠端 --> git push -d origin $(git tag -l "*v3.[2]*-beta*") ``` #### 6. cherry-pick 多個commits ``` <!-- A:commit hash 比 B 舊 --> <!-- -x 記錄來源 --> git cherry-pick A^..B -x ``` ### repo ``` git init ``` ``` git clone ``` ### branch 1. 檢查分支 ``` git branch // 檢查遠端分支 git branch -r ``` 2. 開分支 ``` git branch 分支名 // 開分支且checkout 過去 git checkout -b 分支名 ``` - 批次刪除分支 ``` // delete branch locally git branch | grep "pattern" | xargs git branch -d // delete local branch that is unmerged git branch | grep "pattern" | xargs git branch -D ``` ### 遠端 remote - 將本地既有的repo推上遠端 ``` cd existing_repo git remote add origin https://gitlab.com/conniel1/react-app.git git push -u origin main ``` --- # 安裝 先裝homebrew ``` brew install git ``` # Submodule ``` git submodule init git submodule update --recursive ``` --- # 教學 📖 [git game](https://learngitbranching.js.org/?locale=zh_TW) 📖 [為你自己學git](https://gitbook.tw/)
×
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