Git的使用记录
Git的使用
配置:
git config
是 Git 的一个强大命令。你可以使用 Git 配置文件来定制 Git 的工作方式。
这个文件存在于初始化 Git 的项目目录(/project/.git/config
)或用户根目录(~/.gitconfig
)。
如果没有指定配置,Git 会使用其默认设置。
使用如下命令可配置全局设置:
git config --global Axx.Bxx Cxx
~/.gitconfig
中会新增如下或对应参数发生相应的变化
[Axx]
Bxx = Cxx
-
配置名字与邮箱:
git config --global user.name "name" git config --global user.email "xxxx@xx"
-
其他配置:
-
编辑器设置:
git config --global core.editor "code --wait"
- vi\vim :
"vim"
- vscode :
"code --wait"
- vi\vim :
-
默认显示简短状态
git config --global status.short true
默认情况下,
git status
命令显示你的项目中的变化,并有很长的细节。它的格式是这样的:On branch [branch name] Your branch is up to date with ... Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in the working directory) modified: ... Untracked files: (use "git add <file>..." to include in what will be committed) ... no changes added to commit (use "git add" and/or "git commit -a")
这是一个有指导意义的输出,但有时你只需要一个版本库状态的总结。在
git status
中添加--short
选项,可以得到一个简短的格式化输出。结果会是这样的:
M [file] ?? [file]
“M” 表示已修改,“??” 表示未跟踪。
-
使用:
-
SSH公钥设置
GitHub、Gitee、Gitlab共用一个SSH密钥配置 - OMaster - 博客园 (cnblogs.com)
xxx@xxxx:~$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/dxx/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/dxx/.ssh/id_rsa Your public key has been saved in /home/dxx/.ssh/id_rsa.pub The key fingerprint is: SHA256:lC6rAEq6728cfQzVknlfcodMotLRdat41O4iH8xjNIU dxx@dxx-pc The key's randomart image is: +---[RSA 3072]----+ | +...+o..| | =oooo.B.o| | .+oo. E = | | .o . + + | |.. ..oS . = . | |+. . .oo = o | |o .. ... . B . | | . .o. + + | |.oooo . | +----[SHA256]-----+ xxx@xxxx:~$ cat ~/.ssh/id_rsa.pub ssh-rsa **************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************** xxx@xxxx xxx@xxxx:~$ ssh -T git@github.com The authenticity of host 'github.com (140.82.116.3)' can't be established. ED25519 key fingerprint is SHA256:******************************************** This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'github.com' (ED25519) to the list of known hosts. Hi *********! You've successfully authenticated, but GitHub does not provide shell access. xxx@xxxx:~$ ssh -T git@gitee.com The authenticity of host 'gitee.com (182.255.33.134)' can't be established. ED25519 key fingerprint is SHA256:******************************************** This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'gitee.com' (ED25519) to the list of known hosts. Hi *********! You've successfully authenticated, but GITEE.COM does not provide shell access.