git版本管理全流程命令操作

  • git完整使用流程:
bash 复制代码
# 1. 从远程仓库拉取代码
git clone <repo link>
# 2. 从mian分支创建其他分支
git checkout -b <my_branch>
# 3. 查看main分支最新提交,但不合并(pull会合并merge)
git fetch origin
# 3. 从远程仓库拉取指定分支的更新并合并到当前分支,会产生merge提交
git pull <branch>
# 4. 将自己分支挂到mian分支上同步main分支更新
git rebase origin/main
## 解决了冲突并准备继续
	git rebase --continue
## 不想继续当前的 rebase 操作
	git rebase --abort
# 5. 将自己文件添加到暂存区
git add <my_new_file>
## 查看暂存区状态
	git status
## 将暂存区的文件还原到工作区
	git restore --staged <my_new_file>
## 还原除暂存区外的工作区文件修改(不影响未跟踪的文件/新键未add的文件)
	git restore .
## 还原除暂存区外的工作区所有文件f/目录d修改
	git clean -fd
## 将当前所有未提交的修改(未暂存和暂存的修改)打包存起来并清空现场
	git stash
## 恢复现场
	git stash pop
	git stash apply
# 6. 将自己的文件提交到本地仓库
git commit -m "commit message"
## 将指定 commit 的 file.txt 恢复到当前工作区
	git checkout <commit_id> -- file.txt
## 修改上一次提交
	git commit --amend
## 回退到指定commit处,之后的commit被撤销
	git reset --hard <commit_id>
## 删除commit的更新
	git rm <file>
# 7. 推送本地分支更新到远程仓库
git push origin <my_branch>
# 8. 触发MR,将branch合并到当前分支(会产生merge提交)
git merge <branch>
# 9. 触发PR
gh pr create --base main --head feature-branch --title "功能描述" --body "变更说明"
# 10. 修改仓库路径
git remote -v
git remote set-url origin [new_repo_path]
  • 配置用户
bash 复制代码
# 全局配置
git config --global user.name "你的名字"
git config --global user.email "你的邮箱@example.com"
# 验证
git config --global --list
# 单仓库配置
git config user.name "仓库专用名字"
git config user.email "repo@example.com"
#
git config --list
  • 远程仓库链接
bash 复制代码
# 查看远程仓库
git remote -v
# 修改远程仓库url
git remote set-url origin https://new-url.com/用户名/仓库.git
相关推荐
杨浦老苏1 天前
在线视频播放器YT-DLP Web Player
docker·工具·群晖·下载·多媒体
私人珍藏库3 天前
[Windows] FFmpeg 图形化:EasyFF v0.17
ffmpeg·媒体·工具·软件·win·多功能
白帽子黑客罗哥4 天前
PHPStudy安装“从入门到放弃”?
网络安全·工具·安装教程·phpstudy·网络安全工程师
私人珍藏库5 天前
[Windows] 媒体人工具箱 MTools v0.0.12
媒体·工具·软件·win·多功能
吉哥机顶盒刷机7 天前
硬核玩机:基于ADB的电视盒子应用管理、桌面替换与全能播放器配置
经验分享·adb·工具·桌面替换
NPE~1 个月前
[工具分享]Maccy —— 优雅的 macOS 剪贴板历史管理工具
macos·教程·工具·实用工具
xcLeigh1 个月前
IoTDB 数据导入全攻略:工具、自动加载与 Load SQL 详解
数据库·sql·工具·iotdb·数据导入·loadsql
小哈里1 个月前
【工具】Linux远程开发核心工具,Git命令缩写与SSH常用命令
linux·git·ssh·工具·远程开发
feasibility.1 个月前
用memU bot做飞书ai办公机器人(含本地ollama模型接入+可视化图表mcp)
人工智能·科技·机器人·飞书·工具·agi·mcp
SunnyRivers1 个月前
智能体与工具集成
langchain·工具·智能体