git 學習筆記

2021-09-24 21:53:50 字數 2963 閱讀 6096

建立本地倉庫

$ git init

initialized empty git repository in /users/coconutnut/tree/midgard/localgit/.git/

建立test.txt

$ git add test.txt

$ git commit -m"the first test.txt"

修改test.txt後

$ git status

on branch master

changes not staged for commit:

(use "git add ..." to update what will be committed)

(use "git checkout -- ..." to discard changes in working directory)

modified: test.txt

no changes added to commit (use "git add" and/or "git commit -a")

檢視修改

$ git diff test.txt

diff --git a/test.txt b/test.txt

index 990931d..a20531f 100644

--- a/test.txt

+++ b/test.txt

@@ -1 +1,3 @@

-test localgit

+git is a distributed version control system.

++git is free software.

\ no newline at end of file

提交

檢視日誌

$ git log

commit f5fa5b8fece043af1df9ee1148318ce286c5a913 (head -> master)

author: s xu date: tue jul 2 11:06:23 2019 +0800

the second test.txt

commit eb531336ab4ad344612448cb067b3c366d61e484

author: s xu date: tue jul 2 11:01:35 2019 +0800

the first test.txt

$ git log --pretty=oneline

f5fa5b8fece043af1df9ee1148318ce286c5a913 (head -> master) the second test.txt

eb531336ab4ad344612448cb067b3c366d61e484 the first test.txt

回退到上乙個版本

$ git reset --hard head^

head is now at eb53133 the first test.txt

這時就是第乙個版本了如果想回到上上個版本就是head^^,以此類推,但是我們要會推到好幾十前的版本或者上100個版本時,別擔心,你可以寫成head~100。

回到第二個版本

$ git reset --hard f5fa5b8

head is now at f5fa5b8 the second test.txt

$ cat test.txt

git is a distributed version control system.

git is free software.ss-macbook-pro:localgit coconutnut$

檢視日誌

$ git reflog

f5fa5b8 (head -> master) head@: reset: moving to f5fa5b8

eb53133 head@: reset: moving to head^

f5fa5b8 (head -> master) head@: commit: the second test.txt

eb53133 head@: commit (initial): the first test.txt

檢視緩衝區內檔案

$ git ls-files

test.txt

刪除檔案

$ git rm test.txt

rm 'test.txt'

設定username和email

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

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

建立ssh key

$ ssh-keygen -t rsa -c "[email protected]"
檢視.ssh/id_rsa.pub

$ cat .ssh/id_rsa.pub
github新增ssh key

…驗證鏈結

$ ssh -t [email protected] 

hi coconutnutx! you've successfully authenticated, but github does not provide shell access.

Git學習筆記

git stash git stash list 顯示git棧內的所有備份,可以利用這個列表來決定從那個地方恢復。git stash clear 清空git棧。此時使用gitg等圖形化工具會發現,原來stash的哪些節點都消失了。關於git stash的詳細解釋,適用場合,這裡做乙個說明 使用git...

git 學習筆記

1 git checkout master 切換分支 2 git checkout b xx 新建分支,同時切換到該分支 3 dev 4 git add a 將變動檔案,提交到index 5 git commit m 將 暫存區 檔案,加入到版本控制中。6 git checkout master 7...

Git 學習筆記

顯示版本庫.git所在的目錄 git rev parse git dir 顯示工作區的根目錄 git rev parse show toplevel 相對於工作區根目錄的相對目錄 git rev parse show prefix git config 命令各引數的區別 git config e 版...