转自: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. BibTex相关

    标签(空格分隔): 杂七杂八的问题 又到了写论文的高峰期(?)在BibTeX中添加参考文献时,发现选项很多,对一些称呼还是一脸懵逼..阿一古,也许是最后一次写论文了,还弄清楚的还是清楚一下吧~ [转自 ...

  2. python beautifulsoup/xpath/re详解

    自己在看python处理数据的方法,发现一篇介绍比较详细的文章 转自:http://blog.csdn.net/lingojames/article/details/72835972 20170531 ...

  3. PHP是什么?

    PHP是什么? PHP是一门后端动态解释型计算机高级语言,一般用来编写或者生成动态网页,主要负责数据的处理与渲染.(这里是指用PHP嵌入网页里面的形式,现在可以直接用一些JS的框架去渲染网页数据了,P ...

  4. BZOJ 2580: [Usaco2012 Jan]Video Game

    2580: [Usaco2012 Jan]Video Game Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 142  Solved: 96[Subm ...

  5. debian7编译安装tengine添加lua和ldap模块

    1.安装开发环境 # aptitute update # aptitude install -y build-essential # aptitude install -y libldap2-dev ...

  6. 解题:ZJOI 2013 K大数查询

    题面 树套树,权值线段树套序列线段树,每次在在权值线段树上的每棵子树上做区间加,查询的时候左右子树二分 本来想两个都动态开点的,这样能体现树套树在线的优越性.但是常数太大惹,所以外层直接固定建树了QA ...

  7. golang管道

    golang中的channel channel用于goroutine之间的通信 如果不用channel,使用共享全局变量的方式,需要加锁 // synchornized 同步 // golang中的 ...

  8. POI的XWPFParagraph.getRuns分段问题 多余逗号

    POI的XWPFParagraph.getRuns分段问题 2018年08月28日 09:49:32 银爪地海贼 阅读数:376   这是我的模板 后台打印出来是分段的 造成这样的原因是${name} ...

  9. openwrt<转载--openwrt框架分析 >

    这次讲讲openwrt的结构. 1. 代码上来看有几个重要目录package, target, build_root, bin, dl.... ---build_dir/host目录是建立工具链时的临 ...

  10. ssh或scp自动化问题

    http://note.youdao.com/noteshare?id=1ac4cb9469f818dbe579d721aae4e914