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
相关推荐
保持当下2 天前
分享一些程序员很棘手但是却又简单的工具
程序员·免费·js·工具
私人珍藏库2 天前
[Android] FX Player-安卓全格式播放器-比MX播放器好用
android·学习·工具·软件·多功能
cup113 天前
[开源] Memory Checker:极致轻量的 Windows 托盘内存监测工具,告别内存焦虑
python·内存·工具·任务管理器·托盘
私人珍藏库3 天前
[Android] OldRoll复古胶片相机高级版-徕卡-哈苏-宝丽来等等
数码相机·智能手机·app·工具·软件·多功能
孟郎郎4 天前
2026 年 15 款 AI 视频生成工具推荐
人工智能·ai·工具·ai视频
私人珍藏库4 天前
[Android] 精图地球-高清卫星3D街景VR地图工具
智能手机·app·工具·软件·多功能
私人珍藏库4 天前
[Android] 视频下载鸟 v20.02 会员
android·人工智能·智能手机·app·工具·多功能
私人珍藏库4 天前
[Android] 三维山水全景地图-3D地形全景观测地图
android·3d·app·工具·软件·多功能
什仙5 天前
Mathcad Prime 的教程资料
学习·工具
私人珍藏库5 天前
【Android】BotHub-多模型AI机器人聚合库-内置免费模型
android·人工智能·智能手机·app·工具·多功能