Git跟SVN最大不同的地方就是分布式。SVN的集中式与Git的分布式决定各自的业务场景。既然是分布式的,那么大部分操作就是本地操作。一般Git操作都是通过IDE,比如Eclipse,如果装了Git Bash,也可以通过命令行操作(不建议使用Git Bash的界面操作)。Git Bash下载地址:https://www.git-scm.com/download,打开后点右边的Downloader XXX for Windows,选择适合自己操作系统的版本下载。

  选择安装目录,一路默认过去,安装后就可以使用Git Bash了,下面列出常用的命令:

  1. 下载(git clone):从github上通过代码路径下载到本地

wulf@wulf00 MINGW64 ~
$ git clone ssh://git@gitlab.cmread.com:2022/newportal/ms-activity-service.git
Cloning into 'ms-activity-service'...
Warning: Permanently added the RSA host key for IP address '[112.13.170.217]:2022' to the list of known hosts.
remote: Counting objects: , done.
remote: Compressing objects: % (/), done.
remote: Total (delta ), reused (delta )
Receiving objects: % (/), 182.48 KiB | 6.76 MiB/s, done.
Resolving deltas: % (/), done.

  2. 查看工作区的文件状态(git status):先进入下载到本地的git工作仓库,查看状态

wulf@wulf00 MINGW64 ~
$ cd C:/Users/wulf/ms-activity/ wulf@wulf00 MINGW64 ~/ms-activity (master)
$ git status
On branch master No commits yet nothing to commit (create/copy files and use "git add" to track)

  3. 将新增的文件或者修改过的文件加入暂存区(git add):先创建一个文件,然后添加文件到暂存区,最后查看工作区状态:

wulf@wulf00 MINGW64 /e/workspace/Wireless-Router/test-pilling/src/test/resources (master)
$ vi test.xml wulf@wulf00 MINGW64 /e/workspace/Wireless-Router/test-pilling/src/test/resources (master)
$ git add test.xml
warning: LF will be replaced by CRLF in test-pilling/src/test/resources/test.xml.
The file will have its original line endings in your working directory. wulf@wulf00 MINGW64 /e/workspace/Wireless-Router/test-pilling/src/test/resources (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'. Changes to be committed:
(use "git reset HEAD <file>..." to unstage) new file: test.xml Untracked files:
(use "git add <file>..." to include in what will be committed) ../../../../.project
../../../../.settings/
../../../../memcache-view/.classpath
../../../../memcache-view/.gitignore
../../../../memcache-view/.project
../../../../memcache-view/.settings/
../../../.classpath
../../../.gitignore
../../../.project
../../../.settings/ wulf@wulf00 MINGW64 /e/workspace/Wireless-Router/test-pilling/src/test/resources (master)

  4. git add . (将当前工作区的所有修改过的文件加入暂存区):这个.代表当前工作区,批量操作

  5. 将暂存区的文件提交到本地Git仓库(git commit):这里提交的是本地仓库,不是远程仓库

wulf@wulf00 MINGW64 /e/workspace/Wireless-Router/test-pilling/src/test/resources (master)
$ git commit -m "test commit"
[master 739bfa3] test commit
Committer: Jimmy Wu(吴林锋) <wulf@inspur.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file: git config --global --edit After doing this, you may fix the identity used for this commit with: git commit --amend --reset-author file changed, insertions(+)
create mode test-pilling/src/test/resources/test.xml

  6. 将本地Git仓库的文件提交到远程仓库(git push):这一步才是提交到远程仓库

  7. 将远程的文件更新到本地仓库 (git fetch)

  8. 将本地仓库的文件合并到当前工作区 (git merge)

  9. 将远程的文件更新到本地仓库,然后合并到当前工作区 (git pull):git pull = git fetch + git merge

wulf@wulf00 MINGW64 /e/workspace/Wireless-Router/test-pilling/src/test/resources (master)
$ git pull
Already up to date.

  10. 创建文支 (git branch)

  11. 切换分支、覆盖文件 (git checkout):git checkout即可切换分支(参数是分支名),也可恢复文件(参数是文件名),比如我修改了test.xml并commit了,后面又决定不改了

wulf@wulf00 MINGW64 /e/workspace/Wireless-Router/test-pilling/src/test/resources (test-branch)
$ git checkout test.xml

  12. 在当前分支创建新的分支(git checkout -b):git checkout –b  test-branch = git branch test-branch + git checkout test-branch

wulf@wulf00 MINGW64 /e/workspace/Wireless-Router/test-pilling/src/test/resources (master)
$ git checkout -b test-branch
Switched to a new branch 'test-branch'

  13. 将test-branch分支合并到主干分支(master)上:先切换(合入哪里先切换到哪里),再合入

wulf@wulf00 MINGW64 /e/workspace/Wireless-Router/test-pilling/src/test/resources (test-branch)
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by commit.
(use "git push" to publish your local commits) wulf@wulf00 MINGW64 /e/workspace/Wireless-Router/test-pilling/src/test/resources (master)
$ git merge test-branch
Already up to date.

  14. 删除分支:

wulf@wulf00 MINGW64 /e/workspace/Wireless-Router/test-pilling/src/test/resources (master)
$ git branch -d test-branch
Deleted branch test-branch (was 739bfa3).

  15. 删除文件(git rm):删除暂存区分支上的文件, 同时工作区也不需要这个文件了,如果本地还想保留文件,需要加上参数cached

wulf@wulf00 MINGW64 /e/workspace/Wireless-Router/test-pilling/src/test/resources (master)
$ git rm test.xml
rm 'test-pilling/src/test/resources/test.xml'

  下面是已经git add到暂存区,想从暂存区删掉.classpath这个文件,又不想commit到本地仓库了,同时不想删掉本地这个文件

wulf@wulf00 MINGW64 /e/workspace/TeaPot (master)
$ git rm --cached .classpath
rm '.classpath'

  16.加入不想提交的文件列表:在当前仓库目录下编辑.gitignore文件

wulf@wulf00 MINGW64 /e/workspace/TeaPot (master)
$ vi .gitignore
wulf@wulf00 MINGW64 /e/workspace/TeaPot (master)
$ cat .gitignore
/target/
.gitignore
.project
dependency-reduced-pom.xml
/.settings/
/bin/

  以上文件列表都不会被git add到暂存区。

    

最新文章

  1. 【完全开源】知乎日报UWP版(下篇):商店APP、github源码、功能说明。Windows APP 良心出品。
  2. 前端开发面试题收集(js部分)
  3. 一、CoreAnimation之图层树详解
  4. 启动tomcat时,报错:IOException while loading persisted sessions: java.io.EOFException解决方法
  5. linq 实现动态 orderby
  6. hduoj 3459 Rubik 2&#215;2&#215;2
  7. Football Foundation (FOFO) TOJ 2556
  8. Redis客户端之Spring整合Jedis,ShardedJedisPool集群配置
  9. FC 坦克大战 老巢铁墙
  10. 从士兵到程序员再到SOHO程序员
  11. Java IO (2) - OutputStream
  12. children真的没有兼容性问题吗?
  13. 多系统重装其中Win7后的启动引导列表恢复
  14. 切换Ubuntu系统python默认版本的方法
  15. Ocelot中文文档-日志
  16. 对HTML5标签的认识(三)
  17. 05解决flask循环引用的问题
  18. IE 浏览器旧版本下载
  19. Java 中断
  20. Linux学习笔记:使用ftp命令上传和下载文件

热门文章

  1. iOS日常学习 - 让你的 Xcode8 继续使用插件
  2. 重装window 7系统,从做一个u盘启动盘,到装系统,很不错
  3. windows 环境下安装python MySQLdb
  4. Pandas描述性统计
  5. Spring Boot的核心
  6. 使用springmvc报错Required int parameter &#39;age&#39; is not present
  7. MVVM架构说明1
  8. HDU-1007-最小公共点对
  9. Django中ORM模板常用属性讲解
  10. SqlServer表死锁的解决方法