Ubuntu12.04 GIT安装和使用

一.安装GIT和配置GIT

1.安装GIT

1
apt-get install git

2.配置GIT

1
2
3
4
5
6
7
8
9
10
11
##配置用户信息
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
##文本编辑器
git config --global core.editor emacs
##差异分析工具
git config --global merge.tool vimdiff
##查看配置信息
git config --list
##获取帮助
git help config

二、创建GIT仓库和远程仓库的使用

1.在工作目录中初始化新仓库

1
2
3
4
5
6
7
##切换到工作目录
mkdir test
cd test
git init
##初始化后可以看到这些文件
ls ./.git/
branches config description HEAD hooks info objects refs

2.从现有仓库克隆出来

1
git clone git://192.168.1.1/var/www/test.git

3.克隆到本地

1
git clone /var/www/test test_new

4.远程仓库的克隆

1
git clone root@192.168.1.1:/var/www/test

5.查看当前的远程库

1
git remote -v

6.添加远程仓库和推送

1
2
3
4
5
6
7
8
##添加远程仓库分支
git remote add test root@192.168.1.1:/var/www/test
##从远程仓库抓取数据
git fetch test
##推送数据到远程仓库
git push origin master
##查看远程仓库信息
git remote show origin

7.远程仓库的删除和重命名

1
2
3
4
##重命名
git remote rename test test_new
##删除
git remote rm paul

三、GIT全局配置

1.配置当前用户名和邮箱

1
2
git config --global user.name "linzhenjie"
git config --global user.email linzhenjie@live.com

2.设置别名

1
2
git config --global alias.ci commit
git config --global alias.st status

3.其他配置

1
2
3
4
5
6
##颜色显示
git config --global color.ui true
##编辑器
git config --global core.editor vim
##独立忽略文件
git config --global core.excludesfile /home/linzhenjie/.gitignore

四、GIT中相关命令

1.检查当前文件状态

1
git status

2.往暂存库中添加新的文件

1
git add test.php

3.提交更新

1
2
3
4
5
6
##提交更新
git commit -m "add test file for my test"
##添加并提交更新
git commit -a -m 'added new benchmarks'
##执行一次空白提交
git commit --allow-empty -m "who does commit?"

4.比较差异

1
2
3
4
5
6
7
##暂存库与版本库比较
git diff
##本地库与暂存库比较
git diff HEAD
##暂存库与版本库比较
git diff --cached
git diff --staged

5.修改最后一次提交

1
2
3
git commit -m 'initial commit'
git add test.php
git commit --amend

6. 查看提交历史

1
2
3
4
##查看所有日志
git log
##查看所有日志(包含重置的日志)
git reflog show master

7.重置/回退暂存区和版本库

1
2
3
4
5
6
##重置/回退版本库
git reset --soft
##重置/回退版本库、暂存库
git reset
##重置/回退版本库、暂存区、工作区
git reset --hard

8.清理工作区

1
2
3
4
##查看不在暂存区的工作区文件
git clean -nd
##清理工作区多余文件
git clean –fd

9.删除暂存区和版本库

1
2
3
4
##删除暂存库和版本库的文件
git rm test.php
##删除版本库的文件
$ git rm --cached test.php

10.移动文件

1
git mv test.php test_new.php

11.进度的存储和恢复

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
##保存当前进度
git stash save
##查看当前进度列表
git stash list
##弹出恢复工作区进度
git stash pop
##弹出恢复工作区和暂存区进度
git stash pop --index
##应用工作区进度
git stash apply
##删除一个进度
git stash drop
##删除所有存储进度
git stash clear
##存储分支进度
git stash branch

五、忽略文件语法

1
2
3
4
5
6
.gitignore
*.a            ##忽略以.a为节结尾的文件
!lib.a        ##不会忽略lib.a的文件或目录
/DIR          ##忽略当前目录下文件(不包括子目录)
DIR/          ##忽略当前目录下所有文件
DIR/*.txt     ##忽略DIR下的txt文件(不包括子目录)
posted @   linzj  阅读(3782)  评论(0编辑  收藏  举报
编辑推荐:
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
阅读排行:
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!
· 用 C# 插值字符串处理器写一个 sscanf
点击右上角即可分享
微信分享提示