版本記錄
版本號 | 時間 |
---|---|
V1.0 | 2022.04.05 星期二 清明節(jié) |
前言
git
是程序員常用的工具,用來進行代碼的管理工作引矩。大家可以看下git的官網娩怎。接下來這幾篇我們就一起學習git检诗。感興趣的可以看下面幾篇涣达。
1. git的使用(一) —— git的配置(一)
寫在前面:這個日子吐葵,對于很多家庭都會很難受吧,有些親人再也回不來了工闺。
git命令總覽
我們在終端中輸入git
乍赫,然后回車瓣蛀,系統(tǒng)就會提示所有的git
指令。
xxxMacBook-Pro ~ % git
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[--super-prefix=<path>] [--config-env=<name>=<envvar>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
restore Restore working tree files
rm Remove files from the working tree and from the index
sparse-checkout Initialize and modify the sparse-checkout
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
diff Show changes between commits, commit and working tree, etc
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
commit Record changes to the repository
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
reset Reset current HEAD to the specified state
switch Switch branches
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.
git config 查看配置信息
config
配置有system
級別 global
(用戶級別)和local
(當前倉庫)三個設置先從system -> global -> local
底層配置會覆蓋頂層配置雷厂,分別使用--system/global/local
可以定位到配置文件惋增。
查看系統(tǒng)config
git config --system --list
查看當前用戶(global)配置
git config --global --list
下面是我的電腦的一個輸出示例
xxx@xxxMacBook-Pro ~ % git config --global --list
core.excludesfile=/Users/xxx/.gitignore_global
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
user.name=xxx
user.email=xxx@xxx.com
commit.template=/Users/xxx/.stCommitMsg
http.version=HTTP/1.1
查看當前倉庫配置信息
git config --local --list
設置用戶名和郵箱
git config --global user.name "xxx"
git config --global user.email "xxx@xxx.com"
直接打開局部git config文件
在一個git
倉庫里,點一下command + shift + .
命令改鲫,然后就可以看見git文件夾下一級里有一個config
的文件夾
直接打開
可以看見诈皿,就是core、remote
和branch
信息等像棘。
直接打開系統(tǒng)git config文件
直接執(zhí)行command + shift + .
命令
其實稽亏,系統(tǒng)級別的config
文件在如下路徑里。
// xxxx就是電腦用戶名
/Users/xxxx/.gitconfig
我們直接打開
創(chuàng)建新倉庫 - Create a new repository
git clone git@git.xxx.git
cd 一個本地文件夾
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
已經存在的文件夾推送到遠端 - Existing folder
cd existing_folder
git init
git remote add origin git@git.xxx.git
git add .
git commit -m "Initial commit"
git push -u origin master
已經存在的git倉庫推送到遠端 - Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin git@git.xxx.git
git push -u origin --all
git push -u origin --tags
參考文章
后記
本篇主要講述了git常用的命令讲弄,這個會持續(xù)進行更新措左,感興趣的給個贊或者關注~~~~