找回密码
 立即注册
首页 业界区 业界 git版本管理全流程命令操作

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

樊涵菡 2025-9-28 18:39:05

  • git完整使用流程:
  1. # 1. 从远程仓库拉取代码
  2. git clone <repo link>
  3. # 2. 从mian分支创建其他分支
  4. git checkout -b <my_branch>
  5. # 3. 查看main分支最新提交,但不合并(pull会合并merge)
  6. git fetch origin
  7. # 3. 从远程仓库拉取指定分支的更新并合并到当前分支,会产生merge提交
  8. git pull <branch>
  9. # 4. 将自己分支挂到mian分支上同步main分支更新
  10. git rebase origin/main
  11. ## 解决了冲突并准备继续
  12.         git rebase --continue
  13. ## 不想继续当前的 rebase 操作
  14.         git rebase --abort
  15. # 5. 将自己文件添加到暂存区
  16. git add <my_new_file>
  17. ## 查看暂存区状态
  18.         git status
  19. ## 将暂存区的文件还原到工作区
  20.         git restore --staged <my_new_file>
  21. ## 还原除暂存区外的工作区文件修改(不影响未跟踪的文件/新键未add的文件)
  22.         git restore .
  23. ## 还原除暂存区外的工作区所有文件f/目录d修改
  24.         git clean -fd
  25. ## 将当前所有未提交的修改(未暂存和暂存的修改)打包存起来并清空现场
  26.         git stash
  27. ## 恢复现场
  28.         git stash pop
  29.         git stash apply
  30. # 6. 将自己的文件提交到本地仓库
  31. git commit -m "commit message"
  32. ## 将指定 commit 的 file.txt 恢复到当前工作区
  33.         git checkout <commit_id> -- file.txt
  34. ## 修改上一次提交
  35.         git commit --amend
  36. ## 回退到指定commit处,之后的commit被撤销
  37.         git reset --hard <commit_id>
  38. ## 删除commit的更新
  39.         git rm <file>
  40. # 7. 推送本地分支更新到远程仓库
  41. git push origin <my_branch>
  42. # 8. 触发MR,将branch合并到当前分支(会产生merge提交)
  43. git merge <branch>
  44. # 9. 触发PR
  45. gh pr create --base main --head feature-branch --title "功能描述" --body "变更说明"
  46. # 10. 修改仓库路径
  47. git remote -v
  48. git remote set-url origin [new_repo_path]
复制代码

  • 配置用户
  1. # 全局配置
  2. git config --global user.name "你的名字"
  3. git config --global user.email "你的邮箱@example.com"
  4. # 验证
  5. git config --global --list
  6. # 单仓库配置
  7. git config user.name "仓库专用名字"
  8. git config user.email "repo@example.com"
  9. #
  10. git config --list
复制代码

  • 远程仓库链接
  1. # 查看远程仓库
  2. git remote -v
  3. # 修改远程仓库url
  4. git remote set-url origin https://new-url.com/用户名/仓库.git
复制代码
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

您需要登录后才可以回帖 登录 | 立即注册