Git學習筆記(一)

先貼一個有趣又好玩Git學習站點 learnGitBranching

前言

Windows 環(huán)境下 有有兩種Git工具, Git BashGit Shell。這兩種主要的區(qū)別是,Git Bash 是Linux風格的命令行工具,Git Shell 是Windows Power Shell 的風格,可以使用Windows 和Shell的命令來操作。我使用了 Git Bash。

基本配置

配置用戶信息

$ git config --global user.name github username
$ git config --global user.email github email

查看本機 Git 配置信息

$ git config --list
core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
...
user.name=github username
user.email=github email

或者也可以查看某個環(huán)境變量的設(shè)定

$ git config user.name
JJ_Jacob

Git 基礎(chǔ)

獲取項目的Git倉庫

獲取倉庫有兩種方法:一種是直接Clone已有的Git倉庫,另一種是在現(xiàn)存目錄下新建Git倉庫

新建Git倉庫
Administrator@QH-20150523KJHQ /d/java_projects
$ mkdir  git-study
Administrator@QH-20150523KJHQ /d/java_projects
$ cd git-study/
Administrator@QH-20150523KJHQ /d/java_projects/git-study
$ git init
Initialized empty Git repository in d:/java_projects/git-study/.git/

現(xiàn)在是一個空的目錄,先隨便加點東西,新建個README文本文件,然后加入版本控制

$ git add README.md
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory.

Administrator@QH-20150523KJHQ /d/java_projects/git-study (master)
$ git commit -m 'init and add README'
[master (root-commit) aeda323] init and add README
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory.
 1 file changed, 2 insertions(+)
 create mode 100644 README.md

克隆已有倉庫

命令格式為 git clone[url], 比如我將Github的博客Clone到本地

$ git clone git@github.com:Jacob110/Jacob110.github.io.git jacobblog
Cloning into 'jacobblog'...
The authenticity of host 'github.com (192.30.252.130)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of know
n hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

出錯了。查看官網(wǎng) 幫助文檔 意思是如果用 Git Bash的話需要將SSH key 添加到 ssh-agent 中。
如果沒有SSH Key 需要生成一下 這里 Generating SSH keys 也講的很清楚。
最后測試下

$ ssh -T git@github.com
Hi Jacob110! You've successfully authenticated, but GitHub does not provide shel
l access.

現(xiàn)在可以了,繼續(xù)剛才clone倉庫

$ git clone git@github.com:Jacob110/Jacob110.github.io.git jacobblog
Cloning into 'jacobblog'...
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to t
he list of known hosts.
remote: Counting objects: 287, done.
remote: Compressing objects:  63% (91/144)   R
remote: Compressing objects: 100% (144/144), done.
Rremote: Total 287 (delta 21), reused 0 (delta 0), pack-reused 136eceiving objec
Receiving objects: 100% (287/287), 1.66 MiB | 291.00 KiB/s, done.
Resolving deltas:   3% (2/60)
Resolving deltas: 100% (60/60), done.
Checking connectivity... done.

這里clone的時候在本地新建了一個目錄。

Git 文件狀態(tài)

查看文件狀態(tài) git status

Administrator@QH-20150523KJHQ /d/java_projects/jacobblog (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

這是剛才Clone下來的項目,未做任何改動。

現(xiàn)在新建一個文本文件,不提交再看看

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        test.txt

nothing added to commit but untracked files present (use "git add" to track)

顯示剛添加的 test.txtUntracked,提示 add,add 之后再看

$ git add test.txt
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   test.txt

現(xiàn)在已經(jīng)添加到Git 版本控制,也就是可追蹤 tracked,等待被提交。提交下再看看

$ git commit
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean

use "git push" to publish your local commits 提示修改在本地已提交,可以推送到遠程倉庫。

總結(jié),Git 入門,一些初始化配置,本地提交提交修改

$ git config --global []
$ git config --list
$ git init
$ git add
$ git commit
$ git clone [url]
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1. 安裝 Github 查看是否安裝git: $ git config --global user.name "...
    Albert_Sun閱讀 13,863評論 9 163
  • 本文為 Git教程的學習筆記,教程源自廖雪峰的博客。這是一個由淺入深,學完后能立刻上手的Git教程。另,附上另一本...
    七弦桐語閱讀 6,495評論 5 47
  • 山是平凡的 無論高低、無論遠近 從不拒絕觀看 水是平凡的 江海濤濤,溪流潺潺 人近之而聲重,人遠之而音稀 因為平凡...
    駱駝計劃藝術(shù)閱讀 328評論 0 0
  • 據(jù)說,那是一種人生巔峰式的體驗,在所有人以為它不存在的時候,漸漸顯現(xiàn),在失落無比的街頭,流浪者的枕上,漂浮著那些有...
    Chosing_春幸閱讀 337評論 0 0
  • 云平臺訂艙webapi 服務(wù)器地址:http://dev.nbeport.com/xde 1.船司訂艙查詢 獲取L...
    baggio555閱讀 989評論 0 0

友情鏈接更多精彩內(nèi)容