git 常用操作

前端之家收集整理的这篇文章主要介绍了git 常用操作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

codecademy 上的Git教程

  1. git init:初始化一个Git 仓库
  2. Git项目由三部分组成

    • Working Directory:你做所有事情所在的工作区
    • Staging Area:where you'll list changes you make to the working directory,列出你对工作区做出的改变
    • A Repository: where Git permanently stores those changes as different versions of the project,储存项目的不同版本
  3. git status: 查看工作区的变化
  4. git add filename: 添加文件到 staging area;
  5. git diff filename : 查看工作区某文件 与 staging area 对应文件的差别;
  6. git commit:提交staging area 中的文件到库中永久保存;
  7. git log:打印出提交历史
  8. git show HEAD:Git 中 当前所在的commit 称为 HEAD 使用本命令可以查看当前所在HEAD;
  9. git checkout HEAD filename:恢复所修改文件为最后一次add后的状态;
  10. git add filename_1 filename_2 可同时提交多个文件stageing area;
  11. git reset HEAD filename 当某个文件已经提交到了 staging area,想要把它从staging area删除可执行此命令;
  12. git reset SHA:取commit的SHA 前7位即可; 如git reset 1234567,版本回滚到对应commit;
  13. git branch:查看所有分支;*所在的分支为当前分支;
  14. git branch new_branch:创建新分支new_branch,注意这个名字应该和你的用途想匹配;
  15. git checkout branch_name:切换到分支branch_name;
  16. git merge branch_name:合并分支branch_name到当前分支;如果有冲突,会提示冲突,需要手动修改后,再次提交;
  17. git branch -d branch_name:删除某分支;
  18. git clone remote_location clone_name:克隆远程分支,远程分支地址remote_location,克隆到本地之后的命名clone_name;
  19. git remote -v 可以查看当前Git 项目的 多个 远程地址;
  20. git fetch:This command will not merge changes from the remote into your local repository. It brings those changes onto what's called a remote branch..查看,本地分支与远程分支比起来有哪些不同;
  21. git merge origin/master:合并本地master分支和远程master分支;
  22. git 工作流:

    • Fetch and merge changes from the remote
    • Create a branch to work on a new project feature
    • Develop the feature on your branch and commit your work
    • Fetch and merge from the remote again (in case new commits were made while you were working)
    • Push your branch up to the remote for review
  23. git push origin your_branch_name:推送分支到源

猜你在找的Git相关文章