git 基本用法

來源:互聯網
上載者:User

標籤:刪除   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 基本用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.