Git管理本地代码(一)【转】
转自:http://blog.csdn.net/weihan1314/article/details/8677800
版权声明:本文为博主原创文章,未经博主允许不得转载。
安装Git
- $sudo apt-get install git
- $sudo apt-get install git-core
更新Git
- $git clone git://git.kernel.org/pub/scm/git/git.git
安装好git后在终端输入git 命令会显示git命令提示,证明git已经安装成功。
初始化代码仓库
- $mkdir android4.2
- $cd android4.2
- $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文件(全局)
- $cd .git
- $vim config
该配置文件的原始内容为:
- [core]
- repositoryformatversion = 0
- filemode = true
- bare = false
- logallrefupdates = true
在该配置文件中加入以下内容:
- [receive]
- 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'
在代码仓库创建一个说明文档(该文档可以随便创建)
- $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
因此我们需要在初始化代码仓库之后,在仓库中创建一个文件:
实例:
- $touch spec.txt
- $git add spec.txt
- $git commit-a -m "first commit"
- $git push
此时,基本的代码仓库已经创建完成。本地代码仓库的Git库为:/data/Downloads/Git/android4.2/.git
同步代码
创建myprojects目录,同步代码
- $mkdir Download/myprojects
- $git clone /data/Downloads/Git/android4.2/.git
修改文件
- $touch test.txt
(备注:在这里可以编写和更改文件,本文只是讲解Git库的使用,所以只是简单的创建了一个文件)
使用git diff 和 git status 命令可以查看代码当前的状态
提交代码
- $git add test.text
- $git commit -a -m "second commit"
- $git push origin master
查看log信息
- $git log
查看代码仓库中代码是否提交成功
进入代码仓库目录,查看代码提交log
- $cd android4.2
- $git log
能够查看代码提交的log信息,但是却无法看到我们提交的代码,怎么回事呢?
如果使用了git init初始化,则远程仓库的目录下,也包含work tree,当本地仓库向远程仓库push时, 如果远程仓库正在push的分支上(如果当时不在push的分支,就没有问题), 那么push后的结果不会反应在work tree上, 也即在远程仓库的目录下对应的文件还是之前的内容。
使用以下命令即可查看提交的内容
$git reset --hard
回退到当前最新(本地最新)提交的代码信息
Git管理本地代码(一)【转】的更多相关文章
- debian安装git管理本地代码
debian安装git管理本地代码 安装git # aptitude install git-core # aptitude install git-doc git-svn git-email git ...
- Git 管理本地代码【转】
转自:http://www.cnblogs.com/JessonChan/archive/2011/03/16/1986570.html 以前用SVN,不过没有用出感情来:倒是用出不少怨恨:由于没有很 ...
- git管理工具的使用教程
Git入门教程 1. 概述 对于软件版本管理工具,为什么要选择Git? 你真正学会使用Git时, 你就会觉得这个问题的回答是非常自然的.然而当真正需要用文字来回答时,却觉得文字好 ...
- 如何使用git管理代码
如何使用Git管理代码 Git 是开发人员用来向代码库(msstash)中提交代码或者下载远端代码库中代码的工具. 如何使用git向代码库中提交我们修改后的代码呢? 1.如果是第一次使用git,那么需 ...
- 使用Git管理版本
原文地址:廖雪峰的网站 Git 是目前世界上最先进的分布式版本控制系统 Git 的历史 集中式 vs 分布式 集中式的版本库是集中存放在中央服务器的.缺点是必须联网.网速慢的情况就会让人抓狂. 分布式 ...
- 手把手教你使用Git管理你的软件代码
什么是分布式版本控制系统?Git有哪些常用命令?什么是仓库?Git的操作区域包括哪些?Git有哪些常用对象(object)?git rebase和git merge的区别是什么?git reset,g ...
- git 管理
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px "Helvetica Neue"; color: #3e3e3e; bac ...
- 用git管理源代码
自从做iOS开发的一年多以来,之前一直都是用svn进行代码管理.因为工作需要,我也开始用git管理源代码.关于git的基本使用,在此做一个详细的介绍,希望能对初次接触git的人有所帮助! 本篇博客针对 ...
- Linux下,使用Git管理 dotfiles(配置文件)
1.管理你的 dotfiles 作为一个计算机深度使用者,并且长期使用 Linux 作为主要操作系统,折腾各种功能强大的软件是常有的事儿.这些软件有它们各自的配置文件,通常以 . 开头,因此有人管它们 ...
随机推荐
- BZOJ3270 博物馆(高斯消元+概率期望)
将两个人各自所在点视为状态,新建一个图.到达某个终点的概率等于其期望次数.那么高斯消元即可. #include<iostream> #include<cstdio> #incl ...
- 用vim去掉utf-8 BOM
'去掉utf-8 BOM :set nobomb '保留utf-8 BOM :set bomb
- c++11 语言级线程
c++11 语言级线程 线程的创建 用std::thread创建线程非常简单,只需要提供线程函数或函数对象即可,并且可以同时指定线程函数的参数. #define _CRT_SECURE_NO_WARN ...
- 【刷题】BZOJ 2301 [HAOI2011]Problem b
Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. Input 第一行一个整数 ...
- Spring点滴四:Spring Bean生命周期
Spring Bean 生命周期示意图: 了解Spring的生命周期非常重要,我们可以利用Spring机制来定制Bean的实例化过程. -------------------------------- ...
- BZOJ 1898: [Zjoi2005]Swamp 沼泽鳄鱼
1898: [Zjoi2005]Swamp 沼泽鳄鱼 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1085 Solved: 604[Submit][S ...
- Satisfiability of Equality Equations - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Satisfiability of Equality Equations - LeetCode 注意点 必须要初始化pre 解法 解法一:典型的并查集算法 ...
- Go interface{}、类型断言
在 golang 中 interface{} 可用于向函数传递任意类型的变量, 但在函数内部使用的话, 该变量的类型就是 interface{}, 也称为空接口类型 比如我们定义一个函数, 输出字符串 ...
- git的一些常见问题
from:http://hi.baidu.com/mvp_xuan/blog/item/2ba062d8cd2c9fc939012fae.html 关于linux上建库等操作请看文章: http:// ...
- 【Asp.net入门3-02】使用jQuery-jQuery 入门
下面的几小节将介绍jQuery的基础知识.如前所述,不可能仅仅通过一章的内容详细介绍jQuery, 但可以向你说明如何对HTML文档中的内容执行简单的操作,以及更重要的,如何逐步实现本书其他 部分的示 ...