--- tags: Command --- # Git Command ## 暫存修改的檔案 ```git git stash git stash clear # 清除暫存 git stash apply # 加入最近的一次 ``` ## 增加遠端連線 ```git git remote add upstream git@github.com:gomaji/www.gomaji.com.git ``` ## 刪除改過的資料 * tracked file ```git git restore file ``` * untracked file ```git git clean -f # 會把檔案刪掉 ``` ## Branch * 建立分支 ```git git branch issue1 #方法1: issue1為branch名稱 git checkout -b issue1 #方法2: -b 參數執行,可以同時建立分支和切換。 ``` * 切換分支 ```git git checkout issue1 # 建立一個 issue1分支在 local 端,並將其連接到 origin/issue1 的遠端分支 git checkout -b issue1 origin/issue1 ``` * 合併分支的內容 ```git git checkout master git merge issue1 # 把issue1修改的內容merge到master # 這時候master會多出issue1的commit,可以推送到master ``` ```git git checkout your_branch git fetch origin master git merge -s recursive -X theirs origin/master # 把master的commit覆蓋到現在的分支,若有衝突產生則以master的為主 ``` ## 退版本 * 先檢查commit資訊 ```git git log --oneline -10 # 檢查最近10次log的資訊 ``` * 強制退出,不保留原始commit節點的資訊 ```git git reset --hard HEAD~1 # 往前退1版 ``` * 強制推送本地的資料上去 :::warning 會抹去commit紀錄 ::: ```git git push origin branch_you_want -f ``` ## 回復版本 * 先找出commit id ```git git reflog -10 # 檢查最近10次的版本 ``` * 根據commit id 回到該版本 ```git git reset --hard <commit_id> ``` ## 拆掉commit https://gitbook.tw/chapters/using-git/reset-commit.html * 如果最後一個commit是e12d8ef,想對他重做則需要回到他**之前**(85e7e30) ```git git reset 85e7e30 ``` ## 去除rebase *  ```git git rebase --abort ``` ## 忽略某個檔案的改動 ```git # 忽略 git update-index --assume-unchanged xxx文件 #還原 git update-index --no-assume-unchanged xxx文件 ```
×
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