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 作为主要操作系统,折腾各种功能强大的软件是常有的事儿.这些软件有它们各自的配置文件,通常以 . 开头,因此有人管它们 ...
随机推荐
- 远程连接工具SSH和linux的连接
实际开发中,Linux服务器都在其他的地方,我们要通过远程的方式去连接Linux并操作它,Linux远程的操作工具有很多,企业中常用的有Puttty.secureCRT.SSH Secure等.我使用 ...
- mysql的check约束问题
mysql手册中写道:存储引擎会解析check子句,但是会把它忽略掉 The CHECK clause is parsed but ignored by all storage engines. 现在 ...
- MT【161】韦恩图
(清华2017.4.29标准学术能力测试25) 若$N$的三个子集$A,B,C$满足$|A\cap B|=|B\cap C|=|C\cap A|=1$,且$A\cap B\cap C=\varnoth ...
- 洛谷 P1357 花园 解题报告
P1357 花园 题目描述 小\(L\)有一座环形花园,沿花园的顺时针方向,他把各个花圃编号为\(1~N(2<=N<=10^{15})\).他的环形花园每天都会换一个新花样,但他的花园都不 ...
- ZABBIX 3.4 监控Nginx 状态(七)
一.环境准备 1.在nginx的配置文件中,添加status配置 location /nginx_status { stub_status on; ...
- 第五周linux学习笔记
第五章 系统调用 5.1 与内核通信 系统调用在用户空间进程和硬件设备之间添加了一个中间层.该层主要作用有三个. 它为用户空间提供了一种硬件的抽象接口. 系统调用保 证了系统的毡定和安全. 在第 3 ...
- CentOS7单节点部署redis-cluster
准备一台机器,系统版本为CentOS7.(注意本文描述的是redis-cluster,不是主从复制) 1.下载软件包 # wget http://download.redis.io/releases/ ...
- bzoj 2839 : 集合计数 容斥原理
因为要在n个里面选k个,所以我们先枚举选的是哪$k$个,方案数为$C_{n}^k$ 确定选哪k个之后就需要算出集合交集正为好这$k$个的方案数,考虑用容斥原理. 我们还剩下$n-k$个元素,交集至少为 ...
- 【树状数组】【P4113】[HEOI2012]采花
Description 给定一个长度为 \(n\) 的序列,有 \(m\) 次询问,每次询问一段区间,求区间中有多少个数出现次数超过 \(1\) 次 Limitation \(n,~m~\leq~2~ ...
- opencv 启动摄像头 C++
http://blog.csdn.net/thefutureisour/article/details/7530177 在网上看了许多关于OpenCV启动摄像头的资料,但是,都是基于C语言的,代码又臭 ...