入职的第一天,让git命令直接给难住了,汗!使用习惯可视化的工具对于命令行早就忘记的一干二净。还好,回家自己练习一下,总会没有错的。git就不做简介了,版本管理除了svn就是git了,其他的都无所谓了。

直接上命令查看所有的git命令非常简单,直接在控制台输入 git,可以看到:

lswdeMacBook-Pro:GitHub lsw$ git
usage: git [--version] [--help] [-C <path>] [-c name=value][--exec-path[=<path>]] [--html-path] [--man-path] [--info-path][-p|--paginate|--no-pager] [--no-replace-objects] [--bare][--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]<command> [<args>]The most commonly used git commands are:add        Add file contents to the indexbisect     Find by binary search the change that introduced a bugbranch     List, create, or delete branchescheckout   Checkout a branch or paths to the working treeclone      Clone a repository into a new directorycommit     Record changes to the repositorydiff       Show changes between commits, commit and working tree, etcfetch      Download objects and refs from another repositorygrep       Print lines matching a patterninit       Create an empty Git repository or reinitialize an existing onelog        Show commit logsmerge      Join two or more development histories togethermv         Move or rename a file, a directory, or a symlinkpull       Fetch from and integrate with another repository or a local branchpush       Update remote refs along with associated objectsrebase     Forward-port local commits to the updated upstream headreset      Reset current HEAD to the specified staterm         Remove files from the working tree and from the indexshow       Show various types of objectsstatus     Show the working tree statustag        Create, list, delete or verify a tag object signed with GPG'git help -a' and 'git help -g' lists available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.

这里有git常用的命令,如果不知道命令如何使用,那么输入 git help <命令的名称>,比如 git help init,然后回车,控制台中就会输出init命令的详细解释合使用说明。

这里只说几个常用的命令:

1、git clone 从远程服务器上的git版本库克隆到本地。例子:首先进入本地的一个文件夹比如gitHubLib

<p class="p1">lswdeMacBook-Pro:GitHub lsw$ git clone https://github.com/shiweihappy/LearnGItShell.git</p><p class="p1">Cloning into 'LearnGItShell'...</p><p class="p1">remote: Counting objects: 3, done.</p><p class="p1">remote: Compressing objects: 100% (2/2), done.</p><p class="p1">remote: Total 3 (delta 0), reused 0 (delta 0)</p><p class="p1">Unpacking objects: 100% (3/3), done.</p><p class="p1">Checking connectivity... done.</p>

可以看的我将远程服务器上的LearnGItShell这个git仓库克隆到本地的目录文件夹中

2、git pull --rebase 更新git的仓库,有人就问了为什么不是用git pull,加入--rebase是什么意思,这个问题就有点难解释了,有时间的话我会专门写一篇文章介绍这两种方法的区别。如果实在想知道的话可以网上搜索一下,具体这两种方法哪种更好,谁都无法说服谁,萝卜白菜各有所爱吧!

例子:

lswdeMacBook-Pro:<span style="font-family: monospace;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">LearnGItShell</span> lsw$ git pull --rebase
Current branch master is up to date.

3、使用vim命令创建新的文件a.txt

vim a.txt

进入可编辑状态 i

输入对应的内容,推出可编辑状态 esc

保存文件 :wq

4、git status 查看仓库的各个文件的状态。这个命令要多使用,无论是在更新或者提交的时候,可以查看本地的文件修改状况,防止误修改。例子:

lswdeMacBook-Pro:LearnGItShell lsw$ git status
On branch master
Your branch is up-to-date with 'origin/master'.Untracked files:(use "git add <file>..." to include in what will be committed)a.txtnothing added to commit but untracked files present (use "git add" to track)

这里可以看到在本地仓库中提示有一个没有版本控制的文件 a.txt,同时git提示使用add命令将其加入本地仓库中。

5、git add 添加文件到本地仓库中,可以使用 git add a.txt 或者 git add . 将全部文件都加入到本地仓库中。

lswdeMacBook-Pro:LearnGItShell lsw$ git add .
lswdeMacBook-Pro:LearnGItShell lsw$ git status
On branch master
<p class="p1">Your branch is up-to-date with 'origin/master'.</p><p class="p2">
</p><p class="p1">Changes to be committed:</p><p class="p1">  (use "git reset HEAD <file>..." to unstage)</p><p class="p2">
</p><p class="p3"><span class="s1"> </span>new file:   a.txt</p>

使用add命令后,在使用status命令查看本地的文件都在本地的仓库中了。

6、git commit命令,提交修改内容的日志,这个命令很重要,因为通过他可以将这次所有的修改的说明提交到git仓库的log日志中,这也是以后我们查看之前修改的重要依据。例子:

lswdeMacBook-Pro:LearnGItShell lsw$ git commit -m "add a.txt"
[master 9a25f4f] add a.txt1 file changed, 3 insertions(+)create mode 100644 a.txt
lswdeMacBook-Pro:LearnGItShell lsw$ ls
README.md   a.txt
lswdeMacBook-Pro:LearnGItShell lsw$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.(use "git push" to publish your local commits)nothing to commit, working directory clean

这样我们添加的文件的日志就添加到本地仓库的日志中了,同时git提示我们将本地的仓库push到远程的仓库中。OK!继续

7、git push,将本地的修改提交到远程的仓库中。例子:

lswdeMacBook-Pro:LearnGItShell lsw$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:git config --global push.default matchingTo squelch this message and adopt the new behavior now, use:git config --global push.default simpleWhen push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.In Git 2.0, Git will default to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)Username for 'https://github.com': shi_weihappy@126.com
Password for 'https://shi_weihappy@126.com@github.com':
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 283 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/shiweihappy/LearnGItShell.git40ceb9f..9a25f4f  master -> master

其中需要输入远程仓库的UserName合password。

我们输入status命令查看一下当前的状态:

lswdeMacBook-Pro:LearnGItShell lsw$ git status
On branch master
Your branch is up-to-date with 'origin/master'.nothing to commit, working directory clean

OK,远程仓库也提交完毕!

8、最后来一个查看日志的命令git log。直接上例子:

lswdeMacBook-Pro:LearnGItShell lsw$ git log
commit 9a25f4fe7224492c7ba440c3430e27918b8fa5d8
Author: shiweihappy <shi_weihappy@126.com>
Date:   Tue Jan 6 22:24:10 2015 +0800add a.txtcommit 40ceb9fd3bf48bc8f351e60521761a72b9e390a4
Author: shiweihappy <shi_weihappy@126.com>
Date:   Tue Jan 6 22:20:11 2015 +0800Initial commit

第一部分的初级命令就是这么多了,后续还会有更多的命令介绍,敬请期待了!

转载于:https://www.cnblogs.com/shiweihappy/p/4246356.html

Git命令学习总结(-)相关推荐

  1. externalreferences 命令在 sdi 模式下不可用_一个适合新手交互式Git命令学习项目

    前言 在我们日常工作开发中,Git是必不可少的版本控制软件,很多时候我们都用Git来管理我们的项目. 比较常用的有Github,Gitlab,Stash等. 因此对于Git命令的掌握是我们工作必备的能 ...

  2. GIT 命令学习:获取与创建项目

    GIT命令 获取和创建命令 init init主要是用来创建一个git库或者重新初始化一个已经存在的库.这个命令会 创建一个.git目录,其中会包含objects.refs/heads.refs/ta ...

  3. 史上最全Git命令学习:从基础出发,Java中高级面试题总结(全面)

    将暂存区的文件提交本地仓库: 将本地仓库的文件推送到远程仓库: Git文件的四种状态 根据一个文件是否已加入版本控制,可以把文件状态分为:Tracked(已跟踪)和Untracked(未跟踪),而tr ...

  4. 简单git命令学习整理

    抽了空学习了廖雪峰老师git教程,然后对自己学习的几个命令做下笔记. git init : 初始化git仓库,会生成一个隐藏文件. .git ,没有特殊要求就不用去动它了哈. git add XXX( ...

  5. git命令学习笔记1(路飞学城)

    为什么要版本控制呢?... 安装git: 开始创业初期: 当安装git第一次使用时可能会报下述错误: 需要对git进行配置一下,填写用户名和邮箱即可. rebase: 注意:使用rebase时,最好本 ...

  6. git命令学习笔记2(路飞学城)

    新建一个代码仓库,下面适合个人用,邀请别人参加,一般不适合公司. 若是公司的话,应该创建的是一个组织,然后其他成员就可以申请读写权限了.一个组织中可以创建好多项目,然后分别对不同成员之间的权限分配. ...

  7. git命令学习第二站——高级篇

    在高级篇,我们就可以在整个图上自由的游走了.本章主要介绍3个部分:绝对引用,相对引用和撤销更改. 绝对引用 2.1关 这里介绍了一个重要的概念就是HEAD,其实HEAD指向的就是当前的执行的节点,我们 ...

  8. 手把手教最新最全最详细Git使用教程(图文并茂,附Git命令大全学习文档)

    导读 因为教程详细,所以行文有些长,新手边看边操作效果出乎你的预料.GitHub虽然有些许改版,但并无大碍. 最全Git命令学习文档下载(集合整理,非常适合新手) 一.Git是什么? Git是目前世界 ...

  9. git 提交命令_工作总结:Git的学习和使用,最详细的Git教程,从入门到精通

    前言 Git简介 实用主义 深入探索 总结 参考资料 前言 Git 是程序员学习和工作都离不开发工具,今天和大家分享 Git 常用命令总结. Git简介 Git 是一种分布式版本控制系统,它可以不受网 ...

最新文章

  1. UrlDecode和base64
  2. 多容器,Nginx容器灵活切换PHP版本!同时运行多个PHP容器
  3. Qt——P6 QPushButton创建
  4. cocos2D中scheduleOnce的陷阱
  5. JavaScript中一些常用的方法整理
  6. spring连接mysql出现问题_spring+hibernate连接mysql问题啊
  7. [翻译]深入解析Windows操作系统(下)之第十章 内存管理
  8. 精简版Android ProtoBuf入门
  9. Log4j2 Demos(基础/时间大小回滚/定期删除/日志脱敏)
  10. 华为7c手机怎么恢复出厂设置_华为荣耀畅玩7A/7C解锁教程_荣耀畅玩7A/7C用官方解锁码解锁方法...
  11. 计算机科学的主要目标,学习计算机的主要目的是什么?
  12. 搭建完全分布式HBase
  13. 解决nvcc显示不是内部或外部命令的问题
  14. react+antd的后台管理项目模板
  15. 机器码农:深度学习自动编程
  16. MySQL 8.0 执行 insert 插入数据非常缓慢的问题及解决方法
  17. 【経験談】VS2013创建数据库连接失败问题
  18. 大疆19年校招0804笔试A卷
  19. 计算机网络鲍卫兵答案,之江浙工大之江学院1314(1)课程表校区1.doc
  20. 智能时代——大数据与智能革命重新定义未来

热门文章

  1. 算法(第4版) Chapter 5.2 单词查找树
  2. #pragma once 和 #ifndef ... #define ... #endif 的区别
  3. wlan bss ess ssid
  4. bash脚本创建变量_创建一个Bash脚本模板
  5. devops 业务模型_如何为DevOps转型建立业务案例
  6. 中国开放教育资源协会_开放教育不仅仅是开放内容
  7. Vue学习笔记一 创建vue项目
  8. 必备收藏 | 超详细揭秘 Redis 持久化,建议收藏!
  9. 浏览器推送 comet
  10. es6 async函数的语法