標籤:刪除 etc ping 切換 height ref set pull 版本
git
日常拉取代碼,建立和切換分支:
git fetch remote_repo_alias_name branch_name
git merge FETCH_HEAD -m ‘xxx’
上面是比較妥善的辦法:還有git pull origin master 這種比較容易出現代碼合并問題
git checkout -b new_branch 建立並切換本地分支
git checkout other_branch (在同一個git 項目目錄下可以隱藏多個本地分支)
(在本地倉庫建立本地分支,並提交到遠程倉庫,相當於建立了一個遠程分支)
============================================================
SSH KEY 免輸入密碼提交到遠程倉庫(前提先建立了遠程倉庫的使用者)
git config --list
git config user.name
git config --global user.name “username”
git config —global user.email ‘email’
ssh-keygen -t rsa -C “email” 產生公開金鑰和私密金鑰
github/gitlab 上傳公開金鑰
==============================================
第一次拉代碼:
git clone git_remote_url
cd url dir 預設建立master 分支
將代碼存到本地寄存區:
git add .
提交代碼到本地分支:
git commit -m ‘xxxx’
將代碼提交到遠程分支:
git push origin master git push 提交預設遠程分支
建立本地分支:
git branch branch_name
刪除遠程分支:
git push origin <local_branch_name>:<remote_branch_name>
如果 本地分支省略 :remote_branch_name 則會刪除遠程分支(推個空的分支)
git branch -r -d origin/branch-name
git push origin --delete <branchName>
刪除本地分支:
git branch -d branch_name
==============================================================
代碼復原: (參見:http://yijiebuyi.com/blog/8f985d539566d0bf3b804df6be4e0c90.html)
1.沒有存寄存區的
git checkout file (可以用萬用字元)
上面的只能復原檔案中的內容,
如果是新增的檔案或檔案夾可以用:
git clean -fd
2.提交到寄存區 或 本地的
git reset - - hard
3.已經提交到遠程分支的
先 git log 看看提交的記錄 找到要提交的 commit_id
git revert commit_id (前幾位也可)
==============================================
打標籤(其實就是打個曆史版本)
建立本地標籤:
git tag -a V1.0 -m ‘xxxxxx’
查看本地標籤:
git tag
推送到遠程標籤:
git push origin —tags
刪除本地標籤:
git tag -d V1.0
刪除遠程標籤:
git push origin :refs/tags/V1.0
擷取遠程標籤
git fetch origin tag V1.0
git 基本用法