代码版本控制Git工具使用详解
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了代码版本控制Git工具使用详解相关的知识,希望对你有一定的参考价值。
一、Git简介
- Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。
- Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。
- Git 与常用的版本控制工具 CVS, Subversion 等不同,它采用了分布式版本库的方式,不必服务器端软件支持。
二、Git安装
1.centos7安装Git
[[email protected] ~]# yum install -y git
2.查看安装的Git版本
[[email protected] ~]# git --version
git version 1.8.3.1
3.创建git安装目录并初始化
[[email protected] ~]# mkdir /data/git/
[[email protected] ~]# cd /data/git/
[[email protected] git]# git init
Initialized empty Git repository in /data/git/.git/
初始化后在该目录下会生成.git隐藏目录
[[email protected] git]# ls -la
total 0
drwxr-xr-x. 3 root root 18 Apr 8 09:07 .
drwxr-xr-x. 5 root root 45 Apr 8 09:05 ..
drwxr-xr-x. 7 root root 119 Apr 8 09:07 .git
[[email protected] git]# ls .git/
branches config description HEAD hooks info objects refs
4.新建一个test.txt测试文件
[[email protected] git]# vim test.txt
123abc
把本地test.txt文件添加到git仓库
[[email protected] git]# git add test.txt
add后必须执行commit才能真正把文件提交到git仓库里
[[email protected] git]# git commit -m "add new file test.txt"
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account‘s default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got ‘[email protected](none)‘)
修改test.txt
[[email protected] git]# vim test.txt
123abc
456789
[[email protected] git]# git add test.txt
[[email protected] git]# git commit -m "add new file test.txt"
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account‘s default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got ‘[email protected](none)‘)
查看当前仓库中的状态是否有改动的文件
[[email protected] git]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: test.txt
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: test.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .test.txt.swp
以上是关于代码版本控制Git工具使用详解的主要内容,如果未能解决你的问题,请参考以下文章