玖叶教程网

前端编程开发入门

git常用命令备份收藏(git贮藏)

Git 是一个分布式版本控制系统,用于追踪文件和目录的变化。以下是一些 Git 的常用命令:

  1. 初始化一个新的仓库:
  2. git init
  3. 克隆一个仓库:
  4. git clone <repository_url>
  5. 添加文件到暂存区:
  6. git add <file>
  7. 若要添加所有文件,可以使用:
  8. git add .
  9. 提交更改到本地仓库:
  10. git commit -m "Commit message"
  11. 查看当前文件状态:
  12. git status
  13. 查看提交历史:
  14. git log
  15. 创建一个新的分支:
  16. bashCopy code
  17. git branch <branch_name>
  18. 切换到一个分支:
  19. git checkout <branch_name>
  20. 或者使用:
  21. git switch <branch_name>
  22. 创建并切换到一个新的分支:
  23. git checkout -b <new_branch_name>
  24. 或者使用:
  25. git switch -c <new_branch_name>
  26. 合并分支:
  27. git merge <branch_name>
  28. 拉取远程仓库的变化:
  29. git pull
  30. 推送本地更改到远程仓库:
  31. git push
  32. 如果是第一次推送到远程仓库,可能需要使用:
  33. git push -u origin <branch_name>
  34. 查看远程仓库列表:
  35. git remote -v
  36. 查看分支列表:
  37. git branch
  38. 撤销工作区的更改:
  39. git checkout -- <file>
  40. 撤销暂存区的更改:
  41. git reset <file>
  42. 撤销最后一次提交:
  43. git reset HEAD^
  44. 这会将最后一次提交的更改放回工作区。
  45. 删除文件并提交:
  46. git rm <file> git commit -m "Remove file"

这只是 Git 命令的一小部分,Git 提供了丰富的功能来支持版本控制和团队协作。


发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言