git管理-使用入门

来源【原创】 / 908人浏览
时间:2013-03-17 12:15:12
0

使用Git管理你的项目,git是svn的绝佳替代品,可将现有的svn 环境平稳过渡到git环境下。


一、安装git

wget -c http://kernel.org/pub/software/scm/git/git-1.7.6.tar.bz2

tar -jxvf git-1.7.6.tar.bz2

cd git-1.7.6

./configure

make

make install


二、向git系统 注册自己信息和相关操作


git config --global user.name "libo"

git config --global user.email "libo217005@gmail.com"

git init 初始化项目

git add . 添加到项目中 只要涉及到文件的改动,都要先add,才能commit

git commit 提交

git commit -a 提交所有更改,但是新增文件需要先git add

git diff 比较working tree 和 index file 差异

git diff --cached 比较index file 和代码仓库的差异

git status 列出所有更改


将看到如下表述的文件列表


Changes not staged for commit: 更改的文件,尚未提交

Untracked files: 新添加的文件,尚未添加

Changes to be committed: 已经添加,尚未提交

nothing to commit: 没有更改


git log 查看commit log列表

git log -p 详细的log,会列出更改的对比


git 撤销当前的更改

git reset --soft 只撤销 commit,保留 working tree 和 index file。

git reset --hard 撤销 commit、index file 和 working tree,即撤销销毁最近一次的 commit

git reset --mixed 撤销 commit 和 index file,保留 working tree

git reset 和 git reset --mixed 完全一样

git reset - xxxx 用于删除登记在 index file 里的某个文件。


如何让某些文件被git忽略,比如编译过程中生成的 *.o文件


在project目录中添加一个 .gitignore 文件,一行一个,书写忽略的文件或者文件夹

-------------------------------------

如果修改了项目代码,先 git add 你修改过的文件,再 git diff 并 git status 查看确认,然后 git commit 提交,然后输入

你的开发日志,最后 git log 再次确认。


关于git commit 日志的写法:


1 第一行 简要概括,最好不要超过50个字,有时候会将这一行最为邮件标题发送

2 第二行 空行

3 第三行 书写更改的详细细节      


打赏

站内搜索

搜索文章