Git本地端操作

安裝 git請參閱
檢查 git 版本 指令

1
2
git  ---version
git version 2.15.0

git

列出目前設定的參數:git config –list

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//指令:列出目前設定的參數
git config --list
如下
core.excludesfile=~/.gitignore
core.legacyheaders=false
core.quotepath=false
mergetool.keepbackup=true
push.default=simple
color.ui=auto
color.interactive=auto
repack.usedeltabaseoffset=true
alias.s=status
alias.a=!git add . && git status
alias.au=!git add -u . && git status
alias.aa=!git add . && git add -u . && git status
alias.c=commit
alias.cm=commit -m
alias.ca=commit --amend
alias.ac=!git add . && git commit
alias.acm=!git add . && git commit -m
alias.l=log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'
alias.ll=log --stat --abbrev-commit
alias.lg=log --color --graph --pretty=format:'%C(bold white)%h%Creset -%C(bold green)%d%Creset %s %C(bold green)(%cr)%Creset %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
alias.llg=log --color --graph --pretty=format:'%C(bold white)%H %d%Creset%n%s%n%+b%C(bold blue)%an <%ae>%Creset %C(bold green)%cr (%ci)' --abbrev-commit
alias.d=diff
alias.master=checkout master
alias.spull=svn rebase
alias.spush=svn dcommit
alias.alias=!git config --list | grep 'alias\.' | sed 's/alias\.\([^=]*\)=\(.*\)/\1\ => \2/' | sort
include.path=~/.gitcinclude
include.path=.githubconfig
include.path=.gitcredential
diff.exif.textconv=exif
user.name=lara huang
user.email=lara1105huang@gmail.com
core.excludesfile=/Users/larahuang/.gitignore_global
core.autocrlf=false
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
mergetool.sourcetree.cmd=/Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
commit.template=/Users/larahuang/.stCommitMsg
color.ui=true
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=git@github.com:lara1105huang/blog_lara.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main

設定使用者名稱及信箱(總體)

1
2
git config --global user.name、
git config --global user.email

設定查看配置

1
2
git config --global --list
git config --local --list

Git本地端操作

新增版控初始化

1
2
3
4
5
mkdir 資料夾名稱 //新增資料夾名稱
cd 資料夾名稱 //到資料夾內
git init //加入版控,初始化

Initialized empty Git repository in /Users/larahuang/Desktop/2023-10m/newtest/.git/

為什麼我看不到隱藏檔案
Mac=>

如何停止整個版本控制

1
rm -r .git

版控內的忽略檔案(不加入版控寫在這個檔案內)
新增 .gitignore

1
touch .gitignore //新增 .gitignore版控內的忽略檔案

時常檢查狀態

1
git status

取消追蹤

1
git rm --cached <file>

本地端又分為:

工作目錄(Working Directory)
放入暫存區(Stating Area)
1
git add .
### 加入本地端儲存庫
1
git commit -m '版本訊息'
本地端檔案庫(local repo)
1
git commit -am 'message'

檢視 commit 紀錄

1
git log

輸出更簡潔的 log

1
git log —-oneline
# 指令 解析
1 $git config global user.name 配置name
2 $git config global user.email 配置email
1-1查看配置 $ git config --list 列出目前設定的參數
1-2查看配置 $ git config --global --list 查看當前global用戶配置
1-2查看配置 $ git config --local --list 查看當前local用戶配置
3 .gitignore 忽略檔案,新增.gitignore 加入要忽略的檔案
4.1 $ git init 新增版控,初始化
4.2 $ rm -r .git 停止整個版本控制
4.3 $ git add . 放入暫存區
4.4 $ git status 時常檢查狀態
4.5 $ git rm --cached 取消追蹤
4.6 $ git log 檢視 commit 紀錄
4.7 $ git log --oneline 檢視 輸出更簡潔的 log
4.8 $ git log 檔案名稱 檢視 檔案名稱
4.9 $ git rm 檔案名稱 刪除檔案
4.10 $ $ git rm --cached welcome.html 讓檔案不再受 git 版控(並不是刪除!)
4.11 $ git mv
ex. $ git mv welcome.html hello.html
變更檔名
4.12
$ git checkout
ex.切換到最新版本:$ git checkout master
切換版本/分支
4.13
$ git diff
ex.比對工作目錄與暫存區(Stating Area)全部檔案的差異:$ git diff --cached
ex.比對當前文件與暫存區(Stating Area)全部檔案的差異:$ git diff filename
比對工作目錄(Working Directory)與指定 commit 之間的差異 :$ git diff commit-id
比對兩個 commit 之間的差異 $ git diff [commit-id][new commit-id]
比對兩個 branch 之間的差異 $ git diff branch1 branch2
比對工作目錄

git 參考資料