Git

Git

start
echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:tian-home/test.git
git remote add origin git@github.com:tian-home/Math_LinearAlgebra
git push -u origin main

原理
分三个区域:工作区(文件夹)3暂存区、本地仓库
文件状态:未跟踪、未修改、已修改、已暂存

PC初始设置
# 设置自己的名字、邮件地址
$ git config --global user.name "tian-home"
$ git config --global user.email tian-home@outlook.com

$ git config --global credential.helper store

创建仓库
空白文件夹创建
git init
git init my-repo (直接生成一个文件夹仓库)

下载已有github仓库创建
git clone https://github.com/tian-home/Math_LinearAlgebra

主要命令
git init    创建仓库
git status    查看仓库状态
git add     添加到暂存区 (支持通配符  git add file*, *.txt)
git commit    提交

git pull origin main (从github→更新本地)
git ls-files 查看commit后的提交文件列表

git remote show origin     查看当前github链接
git remote rm origin    删除当前链接
git remote -v            查看当前git远程

.gitignore
日志文件、文件夹337861
忽略所有的 .class文件
忽略所有的 .o文件
忽略所有的 .env文件
忽略所有的 .zip文件
忽略所有的 .tar文件
忽略所有的 .pem文件
忽略所有的 .mp4文件
忽略所有的 .avi文件
忽略所有的 .mp3文件

#忽略所有的 .a 文件
*.a

#但跟踪所有的 lib.a,即便你在前面忽略了.a 文件
!lib.a

#只忽略当前目录下的TODO 文件,而不忽略subdir/ToDo
/TODO

# 忽略任何目录下名为 build 的文件夹
build/

#忽略 doc/notes.txt,但不忽略doc/server/arch.txt
doc/* txt

# 忽略 doc/目录及其所有子目录下的 ·pdf 文件
doc/**/*.pdf

不常用命令

回退版本
git reset    git reset --soft/--hard/mixed  (确定工作区、暂存区是否保留)
示例: gite reset --soft werh324245(log信息中的版本号)

查看日志
git log     
git reflog

查看差异
git diff

删除文件
git rm file.txt
git rm --cached file.txt


工具
sourceTree
gitkraken
lazygit
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

Mac github sshkeys

ssh-keygen -t rsa -C "ti---@outlook.com"

ssh-keygen -t ed25519 -C "ti---@outlook.com" 

ssh -T git@github.com   完成后测试 

 

posted @ 2025-02-18 16:54  tianyunchuan  阅读(11)  评论(0)    收藏  举报