博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
git 安装使用
阅读量:7114 次
发布时间:2019-06-28

本文共 3764 字,大约阅读时间需要 12 分钟。

hot3.png

本人window7 64位系统,下载的时候请选择适合自己的版本,虽说图形化页面挺方便,但掌握一些命令操作也是挺好的。

下载msysgit地址:http://code.google.com/p/msysgit/downloads/list

msysgit 自带简单的图形界面。

下载tortoisegit地址:http://code.google.com/p/tortoisegit/wiki/Download?tm=2

 1、下载和安装GIT

  解压后切换到其目录

  $ tar xvfj git-1.7.6.tar.bz2

  $ cd git-1.7.6

  使用默认配置进行安装,如果想修改配置,可以使用 ./configure --help 来获取帮助

  $ ./configure

  $ make

  $ make install

  2、初始化配置

  GIT默认安装在 /usr/local/bin ,安装之后可以验证一下是否安装好

  $ whereis git

  git: /usr/local/bin/git

  $ git --version

  git version 1.7.6

  $ git --help

  首先需要指定用户名和电子邮件地址

  $ git config --global user.name "GIT Admin"

  $ git config --global user.emal

  再验证一下配置信息

  $ git config --list

  user.name=GIT Admin

  core.repositoryformatversion=0

  core.filemode=true

  core.bare=false

  core.logallrefupdates=true

  其实这些配置是存放在个人主目录下的 .gitconfig 文件中的

  $ cat ~/.gitconfig

  [user]

  name = GIT Admin

  email =

  3、建立工程

  本地的任何一个目录建立GIT工程,如果已有工程位于 /home/obugs/projects/orangebugs 目录,就可以把这目录定义为GIT工程

  $ cd /home/obugs/projects/orangebugs

  $ git init

  Initialized empty Git repository in /home/obugs/projects/orangebugs/.git/

  这样就建立了一个名为 .git 的文件夹,这就是GIT用来存储信息和跟踪改动的文件夹。

  $ ls -altr .git

  total 40

  drwxrwxr-x 4 git git 4096 Aug 13 22:39 refs

  drwxrwxr-x 4 git git 4096 Aug 13 22:39 objects

  drwxrwxr-x 2 git git 4096 Aug 13 22:39 info

  drwxrwxr-x 2 git git 4096 Aug 13 22:39 hooks

  -rw-rw-r -- 1 git git 23 Aug 13 22:39 HEAD

  -rw-rw-r -- 1 git git 73 Aug 13 22:39 description

  -rw-rw-r -- 1 git git 92 Aug 13 22:39 config

  drwxrwxr-x 2 git git 4096 Aug 13 22:39 branches

  drwxrwxr-x 36 git git 4096 Aug 13 22:39

  drwxrwxr-x 7 git git 4096 Aug 13 22:39 .

  4、向工程添加和提交文件

  这些动作和CVS、SVN等操作类似

  $ git add *.java *.c

  $ git commit -m 'Initial upload of the project'

  create mode 100755 Orangebugs.java

  create mode 100755 pwm/ui/DataManager.java

  create mode 100755 pwm/ui/PasswordFrame.java

  create mode 100755 pwm/tools/StrongEncryption.java

  create mode 100755 pwm/tools/PasswordStrength.java

  注意如果之前没有使用 git config 指定用户名和电子邮件地址,这里会报错

  $ git commit -m 'Initial upload of the project'

  *** Please who you are.

  Run

  git config --global user.email "you@example.com"

  git config --global user.name "Your Name"

  to set your account's default identity.

  Omit --global to set the identity only in this repository.

  fatal: empty ident not allowed

  5、更改文件和提交改动

  编辑文件、添加或者删除了一些字段

  $ vi Orangebugs.java

  查看和GIT仓库中的文件相比有了那些改动

  $ git diff

  diff --git a/Orangebugs.java b/Orangebugs.java

  index 6166ed1fd82d32 100644

  - a/Orangebugs.java

  +++ b/Orangebugs.java

  @@ -2,7 +2,7 @@

  - public counter=10

  + public counter=55

  如果要提交,需要先确保将文件添加到了临时区域(staging area)然后才能提交,提交时会自动打开系统的默认编辑器,用户添加一些注释后保存并退出编辑器的时候,这些注释就同时提交到仓库中去了

  $ git add Orangebugs.java

  $ git commit

  [master 80f10a9] Added password strength meter functionality

  1 files changed, 56 insertions(+), 7 deletions(-)

  或者,简单一点的方法是使用 git commit -a 把上面两个命令。

  6、查看状态和查看注释

  如果本地的文件和远端GIT仓库上的文件相比没有任何改动,则

  $ git status

  # On branch master

  nothing to commit (working directory clean)

  如果本地做了改动但是没有提交,则

  $ git status

  # On branch master

  # Changes not staged for commit:

  # (use "git add …" to update what will be committed)

  # (use "git checkout - …" to discard changes in working directory)

  #

  # modified: Orangebugs.java

  #

  no changes added to commit (use "git add" and/or "git commit -a")

  另外,可以用下面的命令查看文件历史和以往的注释

  $ git log Orangebugs.java

  commit c919ced7f42f4bc06d563c1a1eaa107f2b2420d5

  Author: GIT Admin

  Date: Sat Aug 13 22:54:57 2011 -0700

  Added password strength meter functionality

  commit c141b7bdbff429de35e36bafb2e43edc655e9957

  Author: GIT Admin

  Date: Sat Aug 13 20:08:02 2011 -0700

关于git@oschina 的操作

182952_Dxgd_346962.jpg

182953_OeaF_346962.jpg

在push的时候需要填写oschina的用户名和密码

182953_47Oi_346962.jpg

转载于:https://my.oschina.net/shunshun/blog/187245

你可能感兴趣的文章
13. 泛型和枚举
查看>>
Django 查漏补缺
查看>>
mysql中key 、primary key 、unique key 与index区别
查看>>
俺的新书《Sencha Touch实战》终于出版了
查看>>
Word 2003从入门到精通第4讲(表格)
查看>>
docker容器故障致无法启动解决实例
查看>>
mysql数据库Too many connections报错排查
查看>>
移動型VR
查看>>
254个VIP时脚本生成keepalived.conf配置文件
查看>>
三种东西永远不要放到数据库里
查看>>
Xwindow System
查看>>
直播疑难杂症排查(9)— 拖动不准
查看>>
搭建基于用户密码认证的Open***
查看>>
精通MVC3摘译(3)-自定义路由系统
查看>>
LINUX下WEBLOGIC卸载
查看>>
Android第三十三期 - Dialog的应用
查看>>
[QTP] 描述性编程
查看>>
php 启动报错
查看>>
解决SecureCRT连接GNS3时SecureCRT标签窗口同名的问题
查看>>
AWS - 通过Snapshot 还原 EC2实例的一些问题
查看>>