# Git - notes ## 目錄 * 安裝 * 設定 * 目前用到的指令 * 設定不需要放在git上的檔案 * 查看檔案中某行是誰更變的 * 救回被刪除的檔案 * 分支 ### 安裝 環境 : Linux ``` sh sudo apt-get install git ``` ### 設定 ``` sh git config --global user.name 'username' git config --global user.email 'username@wefwe' #確認config git config --list #自定義指令 git config --global alias.自定義指令 '指令' ``` ### 目前用到的指令 ``` sh git status git clone 'url.git' #export GIT_SSL_NO_VERIFY=1 顯示CRLfile: none 就添加環境變數 git add filename #git add -p filename 選擇e 可編輯上傳至暫存區的內容 git commit -m 'notes' git push git pull git remote -v # 查看git地址 ``` ### 與fork的專案同步 https://gitbook.tw/chapters/github/syncing-a-fork.html ``` git remote -v git remote add 原始作者名稱 https://github.com/原始專案url git fetch 原始作者名稱 # pull原始作者的code git merge upstream/branch ``` ### 設定不需要放在git上的檔案 ``` sh vim .gitignore /filename #只會限制未推上git的檔案 git update-index --assume-unchanged filename #如果要限制已推上的檔案 直接打指令 git update-index --no-assume-unchanged filename #解除限制 git ls-files -v #顯示限制名單 ``` ### 查看檔案中某行是誰更變的 ``` sh git blame filename #須在該目錄下 , 可代參數例如:git blame -L 1,3 filename ``` ### 救回被刪除的檔案 ``` sh git checkout filename #可代參數例如:git checkout HEAD~2 filename 可以理解成 git checkout filename 並git add filename & git commit git reset HEAD~2 #返回到前2次的版本,查看版本git log --oneline git reset 版本號碼 --mixed/soft/hard #查看返回紀錄 git reflog or git log -g ``` ### 分支 ``` sh git branch #列出分支 git checkout -b cat #建立並前往分支 git merge cat #合併 cat分支到目前的分支 ``` ### push to other port ```bash= ssh -T -P port git@domain sudo nano /home/kevinpc01/.ssh/config Host domain HostName hostnameorip User git Port port IdentitiesOnly yes IdentityFile ~/.ssh/id_rsa git push origin branch ``` ### git stash git stash pop git stash drop 建立遠端branch並連結 git checkout -b fix-failing-tests origin/fix-failing-tests 刪除遠端的branch git push origin :3-issue-afterboot-Connectorinfo 刪除本地得branch git branch -d 3-issue-boot-connectinfo 清除不需要的遠端branch git fetch --prune ### 對於fork來的專案更新根據原專案最新版本並推到自己的origin ```cmd= git remote add upstream <原始项目的仓库URL> git fetch upstream git checkout master git merge upstream/master git push origin master ```
×
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