转自:http://blog.csdn.net/weihan1314/article/details/8677800

版权声明:本文为博主原创文章,未经博主允许不得转载。

 

目录(?)[+]

 

安装Git

  1. $sudo apt-get install git
  2. $sudo apt-get install git-core

更新Git

  1. $git clone git://git.kernel.org/pub/scm/git/git.git

安装好git后在终端输入git 命令会显示git命令提示,证明git已经安装成功。

初始化代码仓库

  1. $mkdir android4.2
  2. $cd android4.2
  3. $git init

git init 和git --bare init 的具体区别参考:http://blog.haohtml.com/archives/12265

提示: Initialized empty Git repository in /data/Downloads/Git/android4.2/.git/证明git仓库(repository)创建成功

配置config文件(全局)

  1. $cd .git
  2. $vim config

该配置文件的原始内容为:

  1. [core]
  2. repositoryformatversion = 0
  3. filemode = true
  4. bare = false
  5. logallrefupdates = true

在该配置文件中加入以下内容:

  1. [receive]
  2. denyCurrentBranch = ignore

加入该配置的目的是:允许使用git push 提交代码到服务器,否则会出现以下异常:

remote: error: refusing to update checked out branch: refs/heads/master

remote: error: By default, updating the current branch in a non-bare repository

remote: error: is denied, because it will make the index and work tree inconsistent

remote: error: with what you pushed, and will require 'git reset --hard' to match

remote: error: the work tree to HEAD.

remote: error:

remote: error: You can set 'receive.denyCurrentBranch' configuration variable to

remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into

remote: error: its current branch; however, this is not recommended unless you

remote: error: arranged to update its work tree to match what you pushed in some

remote: error: other way.

remote: error:

remote: error: To squelch this message and still keep the default behaviour, set

remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

To git@192.168.1.X:/var/git.server/.../web

! [remote rejected] master -> master (branch is currently checked out)

error: failed to push some refs to 'git@192.168.1.X:/var/git.server/.../web'

在代码仓库创建一个说明文档(该文档可以随便创建)

  1. $touch spec.txt

备注:如果初始的代码仓库为空,git push origin master提交代码的时候会出现以下异常:

error: src refspec master does not match any.
error: failed to push some refs to '/data/Downloads/Git/android4.2/.git
因此我们需要在初始化代码仓库之后,在仓库中创建一个文件:

实例:

  1. $touch spec.txt
  2. $git add spec.txt
  3. $git commit-a -m "first commit"
  4. $git push

此时,基本的代码仓库已经创建完成。本地代码仓库的Git库为:/data/Downloads/Git/android4.2/.git

同步代码

创建myprojects目录,同步代码

  1. $mkdir Download/myprojects
  2. $git clone /data/Downloads/Git/android4.2/.git

修改文件

  1. $touch test.txt

(备注:在这里可以编写和更改文件,本文只是讲解Git库的使用,所以只是简单的创建了一个文件)

使用git diff 和 git status 命令可以查看代码当前的状态

提交代码

  1. $git add test.text
  2. $git commit -a -m "second commit"
  3. $git push origin master

查看log信息

  1. $git log

查看代码仓库中代码是否提交成功

进入代码仓库目录,查看代码提交log

  1. $cd android4.2
  2. $git log

能够查看代码提交的log信息,但是却无法看到我们提交的代码,怎么回事呢?

如果使用了git init初始化,则远程仓库的目录下,也包含work tree,当本地仓库向远程仓库push时, 如果远程仓库正在push的分支上(如果当时不在push的分支,就没有问题), 那么push后的结果不会反应在work tree上,  也即在远程仓库的目录下对应的文件还是之前的内容。

使用以下命令即可查看提交的内容
$git reset --hard

回退到当前最新(本地最新)提交的代码信息

Git管理本地代码(一)【转】的更多相关文章

  1. debian安装git管理本地代码

    debian安装git管理本地代码 安装git # aptitude install git-core # aptitude install git-doc git-svn git-email git ...

  2. Git 管理本地代码【转】

    转自:http://www.cnblogs.com/JessonChan/archive/2011/03/16/1986570.html 以前用SVN,不过没有用出感情来:倒是用出不少怨恨:由于没有很 ...

  3. git管理工具的使用教程

    Git入门教程 1.   概述     对于软件版本管理工具,为什么要选择Git?      你真正学会使用Git时, 你就会觉得这个问题的回答是非常自然的.然而当真正需要用文字来回答时,却觉得文字好 ...

  4. 如何使用git管理代码

    如何使用Git管理代码 Git 是开发人员用来向代码库(msstash)中提交代码或者下载远端代码库中代码的工具. 如何使用git向代码库中提交我们修改后的代码呢? 1.如果是第一次使用git,那么需 ...

  5. 使用Git管理版本

    原文地址:廖雪峰的网站 Git 是目前世界上最先进的分布式版本控制系统 Git 的历史 集中式 vs 分布式 集中式的版本库是集中存放在中央服务器的.缺点是必须联网.网速慢的情况就会让人抓狂. 分布式 ...

  6. 手把手教你使用Git管理你的软件代码

    什么是分布式版本控制系统?Git有哪些常用命令?什么是仓库?Git的操作区域包括哪些?Git有哪些常用对象(object)?git rebase和git merge的区别是什么?git reset,g ...

  7. git 管理

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px "Helvetica Neue"; color: #3e3e3e; bac ...

  8. 用git管理源代码

    自从做iOS开发的一年多以来,之前一直都是用svn进行代码管理.因为工作需要,我也开始用git管理源代码.关于git的基本使用,在此做一个详细的介绍,希望能对初次接触git的人有所帮助! 本篇博客针对 ...

  9. Linux下,使用Git管理 dotfiles(配置文件)

    1.管理你的 dotfiles 作为一个计算机深度使用者,并且长期使用 Linux 作为主要操作系统,折腾各种功能强大的软件是常有的事儿.这些软件有它们各自的配置文件,通常以 . 开头,因此有人管它们 ...

随机推荐

  1. Qt——容器类(译)

    注:本文是我对Qt官方文档的翻译,错误之处还请指正. 原文链接:Container Classes 介绍 Qt库提供了一套通用的基于模板的容器类,可以用这些类存储指定类型的项.比如,你需要一个大小可变 ...

  2. Win7剪贴板粘贴汉字显示为乱码的解决办法

    http://blog.csdn.net/tanaya/article/details/8684805 最近2天发现在记事本粘贴的时候汉字都显示为乱码了,很纠结,后面发现是[区域和语言]设置中的“文本 ...

  3. 跟踪分析Linux内核的启动过程--20135334赵阳林

    解决ubuntu下make menuconfig错误问题 http://blog.sina.com.cn/s/blog_726684020100r1oo.html 安装好相关的软件之后,键入make ...

  4. docker attach 和 docker exec

    docker attach docker attach -- Attach to a running container. 常用选项: --sig-proxy=true:Proxy all recei ...

  5. 读论文Machine Learning for Improved Diagnosis and Prognosis in Healthcare

    Deep Learning的基本思想 假设我们有一个系统S,它有n层(S1,…Sn),它的输入是I,输出是O,形象地表示为: I =>S1=>S2=>…..=>Sn => ...

  6. Dockerfile 部署 nodejs

    1.编写.dockerignore 构建镜像时,并不需要node_modules目录等内容,可以使用.dockerignore忽略一些文件 # .dockerignore Dockerfile nod ...

  7. Go_20: Golang 中 time 包的使用

    time包中包括两类时间:时间点(某一时刻)和时常(某一段时间) 1. 时间常量(时间格式化) const ( ANSIC = "Mon Jan _2 15:04:05 2006" ...

  8. 1082 线段树练习 3 && 树状数组区间修改区间查询

    1082 线段树练习 3 题意: 给定序列初值, 要求支持区间修改, 区间查询 Solution 用树状数组, 代码量小, 空间占用小 巧用增量数组, 修改时在 \(l\) 处 $ + val$ , ...

  9. NDKr10的各种BUG

    NDKr10有几个BUG,所以推荐使用NDKr9 bug1:不支持srand() bug2: 链接异常,找不到stpcpy()

  10. 科学计算三维可视化---Mayavi入门(Mayavi介绍和安装)

    Mayavi介绍 是基于VTK开发的可视化软件(更加高效),Mayavi完全由python编写,方便使用,而且可以使用python编写扩展,嵌入到用户程序中 安装要求 VTK >pip3 ins ...