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 作为主要操作系统,折腾各种功能强大的软件是常有的事儿.这些软件有它们各自的配置文件,通常以 . 开头,因此有人管它们 ...
随机推荐
- selenium+python定位元素的方法及使用
selenium的八种定位方法 By.ID 通过id定位 By.CLASS_NAME 通过className定位 By.CSS_SELECTOR 通过CSS定位 By.LINK_TEXT 通过link ...
- Luogu 2801 教主的魔法 | 分块模板题
Luogu 2801 教主的魔法 | 分块模板题 我犯的错误: 有一处l打成了1,还看不出来-- 缩小块大小De完bug后忘了把块大小改回去就提交--还以为自己一定能A了-- #include < ...
- C++中三种传递参数方法的效率分析
众所周知,在C++中有三种参数传递的方式: 按值传递(pass by value) #include <iostream> using namespace std; void swap(i ...
- Merge Intervals - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Merge Intervals - LeetCode 注意点 区间是无序的 每个区间start一定小于end 解法 解法一:首先以start的值从小到大来 ...
- npm publish gives “unscoped packages cannot be private”
解决方法: npm publish --access public 详细参考此处
- bzoj 1914: [Usaco2010 OPen]Triangle Counting 数三角形
USACO划水中... 题目中要求经过原点的三角形数目,但这种三角形没什么明显的特点并不好求,所以可以求不经过原点的三角形数量. 对于一个非法三角形,它离原点最近的那条边连接的两个点所连的两条边一定在 ...
- 2017 3 8 练习赛 t3 路径规划
题目大意是让你在一棵树上找到一条路径使得(路径边权和*路径最小值) 最大. 这道题有两种方法. 1.点分治,考虑过重心的每条路径是否可能成为答案,枚举从根出发的每一条路径中的最小值等于总路径的最小值, ...
- BZOJ 4321 queue2
4321: queue2 Description n 个沙茶,被编号 1~n.排完队之后,每个沙茶希望,自己的相邻的两人只要无一个人的编号和自己的编号相差为 1(+1 或-1)就行: 现在想知道,存在 ...
- 【贪心/Trie】【CF1083B】 The Fair Nut and Strings
Description 有 \(k\) 个长度为 \(n\) 的只含 \(a\) 或 \(b\) 字符串,并不知道它们具体是多少,只知道它们的字典序不小于字符串 \(A\),同时不大于字符串 \(B\ ...
- 编程语言教程书该怎么写: 向K&R学习!
原文地址:Lax Language TutorialsAndrew Binstock 每年在评审Jolt Awards图书的时候,我都会被一些语言教程类图书弄得心力交瘁.从这些年的评审经验来看,这些语 ...