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
相关推荐
johnny2331 天前
远程桌面工具汇总:RustDesk、1Remote、CrossDesk
工具
私人珍藏库1 天前
[Windows] 漫画翻译工具Saber Translator2.5.1
windows·动画·工具·翻译
xixixi777771 天前
了解一个开源网络数据采集软件包——Libcap
网络·安全·工具
KG_LLM图谱增强大模型3 天前
[Nature子刊]浙大SciToolAgent:用知识图谱驱动的科学智能体实现多工具集成
大模型·知识图谱·工具·科学研究·graphrag
私人珍藏库6 天前
小叮当W信助手v0.1.0
pc·工具·软件
br456vv14 天前
Adobe Dimension 2025 (3D可视化设计神器) 解锁版
java·adobe·工具
NFG89C14 天前
Adobe Lightroom Classic 2025解锁版 (专业照片管理)
java·adobe·工具
bb456b14 天前
Snipaste (截图贴图工具) 精准截图 中文免费版
java·工具·贴图
bin915315 天前
AI工具赋能Python开发者:项目开发中的创意守护与效率革命
开发语言·人工智能·python·工具·ai工具
SEO_juper15 天前
2026 AI可见性:构建未来-proof策略的顶级工具
人工智能·搜索引擎·百度·工具·数字营销