为什么会有这篇文章, 纯粹是摆烂摆久了都忘掉了, 总要拿回来看一看, 那不如水篇文章orz. 来自 deepseek
连接远程仓库并推送代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| # 初始化一个新的 Git 仓库 git init
# 克隆一个远程仓库到本地 git clone <repository_url>
# 查看远程仓库 git remote -v
# 添加远程仓库 git remote add origin <repository_url>
# 推送本地分支到远程仓库 git push origin <branch_name>
# 拉取远程仓库的更新 git pull origin <branch_name>
# 从远程仓库获取更新但不合并 git fetch origin
|
分支操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| # 查看所有分支 git branch
# 创建新分支 git branch <branch_name>
# 切换分支 git checkout <branch_name>
# 创建并切换到新分支 git checkout -b <branch_name>
# 合并分支 git merge <branch_name>
# 删除分支 git branch -d <branch_name>
|
基本操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| # 查看当前状态 git status
# 添加文件到暂存区 git add <file_name>
# 添加所有文件到暂存区 git add .
# 提交暂存区的文件到仓库 git commit -m "Commit message"
# 查看提交历史 git log
# 查看简化的提交历史 git log --oneline
|
撤销操作
1 2 3 4 5 6 7 8 9 10 11
| # 撤销工作区的修改 git checkout -- <file_name>
# 撤销暂存区的修改 git reset HEAD <file_name>
# 撤销最近的提交 git reset --soft HEAD~1
# 撤销最近的提交并丢弃更改 git reset --hard HEAD~1
|
服务器配置 git
1 2 3 4 5 6 7 8
| # 设置用户名 git config --global user.name "Your Name"
# 设置用户邮箱 git config --global user.email "your.email@example.com"
# 查看配置 git config --list
|