Git基本命令操作实例

Git官网上有code school, 跟着做,以下是具体的记录:

1. 初始化

git init

//Initialized empty Git repository in /.git/


2. 查看repo当前状态
   查看是否有文件增加,修改等(先新建一个文件octocat.txt)
git status
//# On branch master
 #
 # Initial commit
 #
 # Untracked files:
 #   (use "git add <file>..." to include in what will be committed)
 #
 # octocat.txt

nothing added to commit but untracked files present (use "git add" to track)


3. 将新的文件放入暂存区stage,这样的话文件octocat就被追踪了(管理)
git add octocat.txt

//Nice job, you've added octocat.txt to the Staging Area


4. git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
# new file:   octocat.txt

5. 提交更改
git commit -m "Add cute octocat story"
//
master (root-commit) 20b5ccd] Add cute octocat story
1 file changed, 1 insertion(+)

create mode 100644 octocat.txt


6. 新增一类文件到暂存区stage

git add '*.txt'


7. git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# new file:   blue_octocat.txt
# new file:   octofamily/baby_octocat.txt
# new file:   octofamily/momma_octocat.txt
# new file:   red_octocat.txt

8.  git commit -m 'Add all the octocat txt files'
//
[master 3852b4d] Add all the octocat txt files
4 files changed, 4 insertions(+)
create mode 100644 blue_octocat.txt
create mode 100644 octofamily/baby_octocat.txt
create mode 100644 octofamily/momma_octocat.txt

create mode 100644 red_octocat.txt


9. 查看日志
git log
//
commit 3852b4db1634463d0bb4d267edb7b3f9cd02ace1
Author: Try Git <try_git@github.com>
Date:   Sat Oct 10 08:30:00 2020 -0500

   Add all the octocat txt files

commit b652edfd888cd3d5e7fcb857d0dabc5a0fcb5e28
Author: Try Git <try_git@github.com>
Date:   Sat Oct 10 08:30:00 2020 -0500

   Added cute octocat story


10. 为本地库添加远程仓库

git remote add origin https://github.com/try-git/try_git.git


11. 将本地repo推送到远程库
git push -u origin master
//Branch master set up to track remote branch master from origin.
//he name of our remote is origin and the default local branch name is master. 

//The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do.


12. 从远程库中下拉更新
git pull origin master
//We can check for changes on our GitHub repository and pull down any new changes
 Updating 3852b4d..3e70b0f
   Fast-forward
   yellow_octocat.txt |    1 +
   1 file changed, 1 insertion(+)

          create mode 100644 yellow_octocat.txt


13. 差异比较
git diff HEAD
//the diff of our most recent commit, which we can refer to using the HEAD pointer
diff --git a/octocat.txt b/octocat.txt
index 7d8d808..e725ef6 100644
--- a/octocat.txt
+++ b/octocat.txt
@@ -1 +1 @@
-A Tale of Two Octocats
+[mA Tale of Two Octocats and an Octodog

14. git add octofamily/octodog.txt


15. 查看暂存区的diff

git diff --staged
diff --git a/octofamily/octodog.txt b/octofamily/octodog.txt
new file mode 100644
index 0000000..cfbc74a
--- /dev/null
+++ b/octofamily/octodog.txt
@@ -0,0 +1 @@

+[mwoof


16. 从暂存区中移除octofamily/octodog.txt
git reset octofamily/octodog.txt

//git reset did a great job of unstaging octodog.txt, but you'll notice that he's still there. He's just not staged anymore.


17. undo

git checkout -- octocat.txt


18. 创建分支

git branch clean_up


19. 切换分支

git checkout clean_up


20. 移除文件
git rm '*.txt'

//git rm command which will not only remove the actual files from disk, but will also stage the removal of the files for us.


21. git commit -m "Remove all the cats"


22. git checkout master


23. 合并分支

git merge clean_up


24. 删除分支

git branch -d clean_up


25. 推送到远程库
git push
To https://github.com/try-git/try_git.git
    3e70b0f..fdfa227  master -> master



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 《Git教程廖雪峰PDF》是一本非常受欢迎的学习Git版本控制工具的教程。这本教程由知名的计算机程序员廖雪峰所编写,以简洁明了的语言和实际操作示例,向读者介绍了Git基本概念和使用方法。 这本教程从Git的起源和基础开始介绍,以帮助读者了解为什么Git成为现代软件开发必备的工具。然后,教程详细介绍了Git的安装和配置,包括如何创建和克隆仓库,添加、提交和查看文件的历史记录等等。同时,教程还介绍了如何使用分支、合并、解决冲突等高级功能,以及如何与远程仓库进行交互和协作。 这本教程采用了一种循序渐进的方式,通过一步步的实例演示和练习,帮助读者逐渐掌握Git基本操作和常用命令。并且,教程还涉及了一些高级主题,如打标签、忽略文件、子模块等,以满足读者的不同需求。 廖雪峰作为一位经验丰富的程序员,他在教程中还分享了一些他个人在使用Git过程中的一些心得和建议,这对于读者来说是非常有价值的。总体来说,《Git教程廖雪峰PDF》是一本浅显易懂、实用性强的Git入门教程,适合初学者和有一定基础的开发者阅读和学习。无论是作为参考资料还是学习教程,这本书都能够帮助读者快速掌握Git基本使用技巧,提高版本控制和团队协作能力。 ### 回答2: 《Git教程廖雪峰PDF》是一本由知名程序员廖雪峰编写的关于Git版本控制工具的教程。这本教程以简洁明了的方式,详细介绍了Git的原理、基本操作和常见使用场景。 首先,教程从Git基本概念入手,向读者介绍了Git的核心理念:分布式版本控制,并与集中式版本控制工具进行了对比。接着,教程详细介绍了如何安装Git,并通过简单的命令操作演示了基本Git使用方法,如创建仓库、添加文件、提交变更等。 除了基本操作,教程还介绍了Git工作区、暂存区和版本库的概念,以及常用的分支管理策略。同时,教程还重点讲解了远程仓库的使用,包括如何与Github等网站协同工作、如何进行分支合并和冲突解决等。 此外,教程还提供了一些高级应用技巧,如如何使用Git进行代码回滚、如何管理大型项目等。同时,教程中穿插了一些案例和示例,帮助读者更好地理解和应用Git。 总的来说,《Git教程廖雪峰PDF》是一本很好的入门教程。通过该教程的学习,读者可以了解Git基本概念和操作方法,同时也能够掌握一些高级应用技巧。该教程以简单易懂的语言和清晰明了的实例,使得读者可以较快地上手Git,并在实际项目中应用所学知识。无论是初学者还是有一定经验的开发者,都能够从《Git教程廖雪峰PDF》中获得实用的Git技巧和经验。 ### 回答3: 《Git教程廖雪峰pdf》是一本详细介绍Git版本控制系统的教程,由知名程序员、技术作者廖雪峰所著。教程总共分为五个部分,包括了Git基本概念、安装与配置、基础操作、团队协作和Git衍生工具。 在这本教程中,廖雪峰首先介绍了Git基本概念,包括仓库、提交、分支、合并等。通过这些概念的解释,读者可以对Git的工作原理有一个初步的了解。 然后,廖雪峰详细介绍了Git的安装与配置,包括了Windows、Mac和Linux系统的安装步骤,以及Git基本配置和常用命令。这部分内容对于初学者来说非常实用,可以帮助他们快速入门Git。 接着,廖雪峰介绍了Git的基础操作,包括了创建仓库、提交修改、查看修改记录等。通过这些操作的演示,读者可以掌握Git基本使用方法。 在团队协作部分,廖雪峰教授了使用远程仓库进行团队协作的方法,例如克隆远程仓库、推送修改、拉取更新等。这部分内容对于多人协作或开源项目的参与者来说尤为重要,可以帮助他们高效地进行代码管理与版本控制。 最后,廖雪峰介绍了一些基于Git的衍生工具,如GitHub、GitLab和Bitbucket等。这些工具提供了更多的协作和管理功能,能够帮助开发者更好地利用Git进行项目管理和版本控制。 总的来说,《Git教程廖雪峰pdf》是一本非常实用的Git入门教程,对于初学者或有一定经验的开发者来说都非常有帮助。通过学习这本教程,读者可以快速掌握Git基本操作和团队协作的方法,从而更好地管理和控制代码的版本。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值