版本记录
版本号 | 时间 |
---|---|
V1.0 | 2022.04.05 星期二 清明节 |
前言
git
是程序员常用的工具,用来进行代码的管理工作。大家可以看下git的官网。接下来这几篇我们就一起学习git。感兴趣的可以看下面几篇。
1. git的使用(一) —— git的配置(一)
写在前面:这个日子,对于很多家庭都会很难受吧,有些亲人再也回不来了。
git命令总览
我们在终端中输入git
,然后回车,系统就会提示所有的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
可以定位到配置文件。
查看系统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
信息等。
直接打开系统git config文件
直接执行command + shift + .
命令
其实,系统级别的config
文件在如下路径里。
// xxxx就是电脑用户名
/Users/xxxx/.gitconfig
我们直接打开
创建新仓库 - 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常用的命令,这个会持续进行更新,感兴趣的给个赞或者关注~~~~