0
点赞
收藏
分享

微信扫一扫

git常用命令大全

北溟有渔夫 2024-04-29 阅读 10
  1. git init:初始化一个新的 Git 仓库。

    git init
    
  2. git clone:克隆远程仓库到本地。

    git clone <repository_url>
    
  3. git add:将文件添加到暂存区。

    git add <file_name>
    
  4. git commit:将暂存区中的文件提交到本地仓库。

    git commit -m "Commit message"
    
  5. git push:将本地仓库的变更推送到远程仓库。

    git push origin <branch_name>
    
  6. git pull:从远程仓库拉取最新的变更并合并到本地仓库。

    git pull origin <branch_name>
    
  7. git branch:管理分支。

    git branch                        # 列出所有分支
    git branch <branch_name>          # 创建新分支
    git branch -d <branch_name>       # 删除分支
    
  8. git checkout:切换分支或还原文件。

    git checkout <branch_name>        # 切换分支
    git checkout -- <file_name>       # 还原文件到最近一次提交的状态
    
  9. git merge:合并指定分支到当前分支。

    git merge <branch_name>
    
  10. git status:查看仓库当前的状态。

    git status
    
  11. git log:查看提交历史。

    git log
    
  12. git remote:管理远程仓库。

    git remote -v                    # 查看远程仓库列表
    git remote add <name> <url>      # 添加远程仓库
    
  13. git reset:重置当前分支的 HEAD 到指定状态。

    git reset --hard <commit_hash>   # 重置到指定提交
    
  14. git stash:暂存当前工作目录的变更。

    git stash                        # 暂存变更
    git stash apply                  # 恢复暂存的变更
    
  15. git tag:管理标签。

    git tag                         # 列出所有标签
    git tag <tag_name>              # 创建新标签
    

这些是 Git 中常用的一些命令,覆盖了版本控制、分支管理、远程仓库操作等多个方面。

举报

相关推荐

0 条评论