0
点赞
收藏
分享

微信扫一扫

uniapp,实时获取系统时间(动态显示)

Git是一个分布式版本控制系统,广泛应用于软件开发项目中来追踪和控制代码的修改历史。

Git常用命令如下:

  1. 配置用户信息

    # 设置全局用户名和邮箱
    git config --global user.name "Your Name"
    git config --global user.email "youremail@example.com"
  2. 初始化仓库

    # 在当前目录创建一个新的Git仓库
    git init
  3. 克隆仓库

    # 克隆远程仓库至本地
    git clone https://github.com/user/repo.git
  4. 添加文件到暂存区

    # 将某个文件添加到暂存区以准备提交
    git add <file_path>
    # 或者添加所有改动
    git add .
  5. 提交更改

    # 提交暂存区的内容到本地仓库,附带提交信息
    git commit -m "Initial commit or describe your changes here"
  6. 查看状态

    # 检查工作区和暂存区的状态
    git status
  7. 拉取远程更新

    # 获取远程仓库的最新改动并尝试自动合并到当前分支
    git pull origin <branch_name>
  8. 推送更改

    # 将本地分支的更改推送到远程仓库的对应分支
    git push origin <branch_name>
  9. 创建与切换分支

    # 创建并立即切换到新的分支
    git checkout -b new_branch
    # 切换回已有分支
    git checkout <existing_branch>
  10. 查看分支

    # 显示所有本地分支
    git branch
    # 显示所有本地和远程分支
    git branch -a
  11. 解决冲突与合并分支

    # 合并指定分支到当前分支
    git merge other_branch
  12. stash暂存未提交的更改

    # 暂存所有未提交的更改
    git stash
    # 恢复最近暂存的更改
    git stash pop
  13. 查看提交历史

    # 显示提交历史记录
    git log
  14. Cherry-pick

    # 将指定提交应用到当前分支
    git cherry-pick <commit_hash>
  15. 撤销更改

    • 取消暂存区的更改:
      git reset <file_path>  # 将指定文件从暂存区移除,但保留工作区的更改
      git reset HEAD <file_path>  # 类似于上述命令,取消暂存的同时恢复到HEAD版本
    • 回滚工作区的更改:
      git checkout -- <file_path>  # 抛弃工作区对指定文件的更改
  16. 删除文件

    • 从版本库和工作区一起删除:
      git rm <file_path>
      git commit -m "Remove file"
    • 仅从版本库中删除(保留工作区文件):
      git rm --cached <file_path>
      git commit -m "Remove file from repository"
  17. 重命名/移动文件

    git mv <old_file_path> <new_file_path>
    git commit -m "Rename/move file"
  18. 查看不同版本间的差异

    git diff  # 查看尚未暂存的改动
    git diff --staged  # 查看已暂存但未提交的改动
    git diff <commit1> <commit2>  # 查看两个提交之间的差异
  19. 回退到以前的提交

    # 回退到某一提交,并且丢弃之后的所有更改(谨慎操作)
    git reset --hard <commit_hash>
  20. 标签管理

    • 创建标签:
      git tag <tag_name> <commit_hash>  # 标记特定提交
      git tag <tag_name>  # 标记当前HEAD指向的提交
    • 推送标签到远程仓库:
      git push origin <tag_name>
    • 删除标签:
      git tag -d <tag_name>
      git push origin :refs/tags/<tag_name>  # 删除远程标签
  21. stash栈操作

    • 存储未提交的更改并清理工作区(保存现场):
      git stash
    • 列出stash列表:
      git stash list
    • 应用stash中的某个更改:
      git stash apply <stash@{index}>
    • 永久应用并删除stash:
      git stash pop
  22. 子模块操作

    • 添加子模块:
      git submodule add <repository_url> <path_to_submodule>
    • 更新子模块:
      git submodule update --remote
  23. 交互式暂存(添加部分更改)

    git add -p
  24. Rebase(变基)

    # 将feature分支的更改重新应用到master分支上,保持线性历史
    git checkout feature
    git rebase master
    git checkout master
    git merge feature

举报

相关推荐

0 条评论