github學習手記

2021-09-26 00:15:54 字數 2914 閱讀 6470

1. 安裝配置

安裝;配置

$ git config --global user.name "your name"

$ git config --global user.email "[email protected]"

$ ssh-keygen -t rsa -c "[email protected]"
成功的話會在~/下生成.ssh資料夾,進去,開啟id_rsa.pub,複製裡面的key。

回到github上,進入 account settings(賬戶配置),左邊選擇ssh keys,add ssh key,title隨便填,貼上在你電腦上生成的key。

驗證:

$ ssh -t [email protected]
2.上傳/轉殖repository

進入要上傳的倉庫

$ git init //通過git init命令把這個目錄變成git可以管理的倉庫

$ git remote add origin [email protected]:yourname/yourrepo.git

轉殖

git clone /path/to/repository 

git clone username@host:/path/to/repository

$ git remote add origin [email protected]:michaelliao/learngit.git

$ git push -u origin master

3. 修改

$ git add readme.txt

$ git status

$ git diff

$ git commit -m "wrote a readme file"

4. 回退

$ git log #顯示從最近到最遠的提交日誌
在git中,用head表示當前版本,上乙個版本就是head^,上上乙個版本就是head^^,當然往上100個版本寫100個^比較容易數不過來,所以寫成head~100

$ git reset --hard head^

$ git reset --hard 1094a

$ git reflog # 記錄你的每一次命令

$ git checkout -- file #丟棄工作區的修改

命令git checkout -- readme.txt意思就是,把readme.txt檔案在工作區的修改全部撤銷,這裡有兩種情況:

一種是readme.txt自修改後還沒有被放到暫存區,現在,撤銷修改就回到和版本庫一模一樣的狀態;

一種是readme.txt已經新增到暫存區後,又作了修改,現在,撤銷修改就回到新增到暫存區後的狀態。

總之,就是讓這個檔案回到最近一次git commitgit add時的狀態。

$ git reset head readme.txt
用命令git reset head可以把暫存區的修改撤銷掉(unstage),重新放回工作區

5. 分支管理

$ git checkout -b dev

switched to a new branch 'dev'

$ git branch dev

$ git checkout dev

switched to branch 'dev'

$ git branch

* dev # 當前分支

master

$ git branch -d dev

deleted branch dev (was b17d20e).

$ git merge dev

git merge命令用於合併指定分支到當前分支。

$ git branch --set-upstream-to=origin/dev dev

branch 'dev' set up to track remote branch 'dev' from 'origin'.

$ git pull

auto-merging env.txt

conflict (add/add): merge conflict in env.txt

automatic merge failed; fix conflicts and then commit the result.

因此,多人協作的工作模式通常是這樣:

首先,可以試圖用git push origin

推送自己的修改;

如果推送失敗,則因為遠端分支比你的本地更新,需要先用git pull試圖合併;

如果合併有衝突,則解決衝突,並在本地提交;

沒有衝突或者解決掉衝突後,再用git push origin

推送就能成功!

如果git pull提示no tracking information,則說明本地分支和遠端分支的鏈結關係沒有建立,用命令git branch --set-upstream-to

origin/

github建立個人部落格手記

第一步 先總體看下要在本地建立的檔案目錄 jun demo config.yml layouts default html posts 2014 06 26 hello world.html index.html config.yml configuration設定 layouts 模板存放資料夾 ...

Delphi學習手記

本人一直使用c buider,並開發了乙個 商關係管理 的三層應用系統.現公司要求使用delphi,沒辦法只有重新學習pascal語言.便記錄學習的過程,那就叫delphi學習手記吧.1 好象inherit form不行,如果想覆蓋上邊的方法,重寫事件或函式,竟然報錯,不懂先,是不是inherit不...

python學習手記

1.list由小到大排序用list.sort 由大到小排序用list.sort reverse true 2.list逆序用list.reverse 3.list 0 代表list中的第乙個元素,中括號一般用於表示元素位置,表示元素 4.dict中沒有排序的說法,keys用於表示位置,應用時用 6....