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

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

  1. lswdeMacBook-Pro:GitHub lsw$ git
  2. usage: git [--version] [--help] [-C <path>] [-c name=value]
  3. [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
  4. [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
  5. [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
  6. <command> [<args>]
  7.  
  8. The most commonly used git commands are:
  9. add Add file contents to the index
  10. bisect Find by binary search the change that introduced a bug
  11. branch List, create, or delete branches
  12. checkout Checkout a branch or paths to the working tree
  13. clone Clone a repository into a new directory
  14. commit Record changes to the repository
  15. diff Show changes between commits, commit and working tree, etc
  16. fetch Download objects and refs from another repository
  17. grep Print lines matching a pattern
  18. init Create an empty Git repository or reinitialize an existing one
  19. log Show commit logs
  20. merge Join two or more development histories together
  21. mv Move or rename a file, a directory, or a symlink
  22. pull Fetch from and integrate with another repository or a local branch
  23. push Update remote refs along with associated objects
  24. rebase Forward-port local commits to the updated upstream head
  25. reset Reset current HEAD to the specified state
  26. rm Remove files from the working tree and from the index
  27. show Show various types of objects
  28. status Show the working tree status
  29. tag Create, list, delete or verify a tag object signed with GPG
  30.  
  31. 'git help -a' and 'git help -g' lists available subcommands and some
  32. concept guides. See 'git help <command>' or 'git help <concept>'
  33. to read about a specific subcommand or concept.

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

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

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

  1. <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是什么意思,这个问题就有点难解释了,有时间的话我会专门写一篇文章介绍这两种方法的区别。如果实在想知道的话可以网上搜索一下,具体这两种方法哪种更好,谁都无法说服谁,萝卜白菜各有所爱吧!

例子:

  1. 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
  2. Current branch master is up to date.

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

vim a.txt

进入可编辑状态 i

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

保存文件 :wq

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

  1. lswdeMacBook-Pro:LearnGItShell lsw$ git status
  2. On branch master
  3. Your branch is up-to-date with 'origin/master'.
  4.  
  5. Untracked files:
  6. (use "git add <file>..." to include in what will be committed)
  7.  
  8. a.txt
  9.  
  10. nothing 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 . 将全部文件都加入到本地仓库中。

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

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

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

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

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

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

  1. lswdeMacBook-Pro:LearnGItShell lsw$ git push
  2. warning: push.default is unset; its implicit value is changing in
  3. Git 2.0 from 'matching' to 'simple'. To squelch this message
  4. and maintain the current behavior after the default changes, use:
  5.  
  6. git config --global push.default matching
  7.  
  8. To squelch this message and adopt the new behavior now, use:
  9.  
  10. git config --global push.default simple
  11.  
  12. When push.default is set to 'matching', git will push local branches
  13. to the remote branches that already exist with the same name.
  14.  
  15. In Git 2.0, Git will default to the more conservative 'simple'
  16. behavior, which only pushes the current branch to the corresponding
  17. remote branch that 'git pull' uses to update the current branch.
  18.  
  19. See 'git help config' and search for 'push.default' for further information.
  20. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
  21. 'current' instead of 'simple' if you sometimes use older versions of Git)
  22.  
  23. Username for 'https://github.com': shi_weihappy@126.com
  24. Password for 'https://shi_weihappy@126.com@github.com':
  25. Counting objects: 4, done.
  26. Delta compression using up to 4 threads.
  27. Compressing objects: 100% (2/2), done.
  28. Writing objects: 100% (3/3), 283 bytes | 0 bytes/s, done.
  29. Total 3 (delta 0), reused 0 (delta 0)
  30. To https://github.com/shiweihappy/LearnGItShell.git
  31. 40ceb9f..9a25f4f master -> master

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

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

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

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

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

  1. lswdeMacBook-Pro:LearnGItShell lsw$ git log
  2. commit 9a25f4fe7224492c7ba440c3430e27918b8fa5d8
  3. Author: shiweihappy <shi_weihappy@126.com>
  4. Date: Tue Jan 6 22:24:10 2015 +0800
  5.  
  6. add a.txt
  7.  
  8. commit 40ceb9fd3bf48bc8f351e60521761a72b9e390a4
  9. Author: shiweihappy <shi_weihappy@126.com>
  10. Date: Tue Jan 6 22:20:11 2015 +0800
  11.  
  12. Initial commit

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

Git命令学习总结(-)的更多相关文章

  1. Git命令学习之旅——日志和穿梭版本号

    在总结了git命令的基础之后,接下来我们看一下基础的一些进阶内容:删除撤销命令.日志查看命令等 既然有加入文件的功能,那么相相应的肯定有移除文件的功能,命令例如以下:git rm [文件名称] 在输入 ...

  2. 【Todo】git的fast forward & git命令学习 & no-ff

    git的fast-forward在之前的文章有介绍过,但是介绍的不细: http://www.cnblogs.com/charlesblc/p/5953066.html fast-forward方式就 ...

  3. git命令学习总结

    学习git 主要是因为github官网共享的资源很有学习价值.最近转型JAVA,所有特意去学习了下git软件.git软件可以去官网下载最新版本. 进入 git 仓库目录 右击 选中 Git Bash ...

  4. git 命令学习

    last-update: 2016年10月27日 1. git stash 简短描述 当你正在进行项目中某一部分的工作,但是里面的东西处于一个比较杂乱的状态,但是却想要切换到其他分支.问题是,你不想提 ...

  5. git命令学习

    git init:把当前目录变成Git可以管理的仓库git add file:把文件添加到仓库git commit -m "描述语句":把文件提交到仓库git status:该命令 ...

  6. git命令学习汇总

    GIT 版本控制常用命令汇总 git version 查看当前git版本信息 git help 获取全部命令帮助信息 git help <command> 获取指定命令帮助信息 git c ...

  7. Git命令学习笔记

    一.本地代码增,删,改,查,提交,找回git checkout .                //抛弃工作区所有修改git checkout -- <file>    //抛弃工作区& ...

  8. Git命令学习摘要

    1.git init  --初始化git项目 2.git status --查看项目的状态 3.git add filename --添加文件到项目 4.git diff filename --查看工 ...

  9. git命令学习之clone指定分支代码

    今天要拉取一个项目,但是是一个指定分支,本来我以为直接git clone就行,但是发现好像不能,报错: Cloning into 'lecture'...fatal: unable to update ...

随机推荐

  1. 股票交易(DP+单调队列优化)

    题目描述 最近lxhgww又迷上了投资股票,通过一段时间的观察和学习,他总结出了股票行情的一些规律. 通过一段时间的观察,lxhgww预测到了未来T天内某只股票的走势,第i天的股票买入价为每股APi, ...

  2. Thinkphp5.1手册太简单,有的功能用起来不确定结果是否和预料的一样,顾整理记录

    //模板{if false} 1 {else/} //====>可以使用 效果同 {else /} 2 {/if} {if condition="(1 eq 1) and false& ...

  3. ThinkPHP5杂技(一)

    Thinkphp5 assign 传递 " 时 ,前台收到的是 " 和ThinkPHP3.2不一样,3.2收到的是 ”,传递给js时 用的data.replace(new RegE ...

  4. 简单实用jstl实现代码编写

    package com.ceshi; import java.io.IOException; import javax.servlet.jsp.JspException; import javax.s ...

  5. iOS------手势操作(nib文件、纯代码)

    总共有六种手势识别:轻击手势(TapGestureRecognizer),轻扫手势 (SwipeGestureRecognizer), 长按手势(LongPressGestureRecognizer) ...

  6. 【bzoj3261】最大异或和 可持久化Trie树

    题目描述 给定一个非负整数序列 {a},初始长度为 N.       有M个操作,有以下两种操作类型:1.A x:添加操作,表示在序列末尾添加一个数 x,序列的长度 N+1.2.Q l r x:询问操 ...

  7. [AtCoderContest010D]Decrementing

    [AtCoderContest010D]Decrementing 试题描述 There are \(N\) integers written on a blackboard. The \(i\)-th ...

  8. [LOJ#114]k 大异或和

    [LOJ#114]k 大异或和 试题描述 这是一道模板题. 给由 n 个数组成的一个可重集 S,每次给定一个数 k,求一个集合 T⊆S,使得集合 T 在 S 的所有非空子集的不同的异或和中,其异或和  ...

  9. bzoj 1137 [POI2009]Wsp 岛屿

    题目大意 Byteotia岛屿是一个凸多边形.城市全都在海岸上.按顺时针编号1到n.任意两个城市之间都有一条笔直的道路相连.道路相交处可以自由穿行.有一些道路被游击队控制了,不能走,但是可以经过这条道 ...

  10. hdu 4741 Save Labman No.004异面直线间的距离既构成最小距离的两个端点

    Save Labman No.004 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...