1git命令的使用,查看git仓库状态,添加文件到git跟踪,git提交,查看git分支,查看git仓库日志信息,切换git分支,解决git分支合并后出现冲突的问题

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: 1新建一个存储git的文件夹,命令是: toto@toto-K45VD:~$ mkdir gitfolder 2初始化一个git仓库,命令是: toto@toto-K45VD:~$cd gitfolder/ toto@toto-K45VD:~/gitfolder$ls toto@toto-K45VD:~/gitfolder$git init
1新建一个存储git的文件夹,命令是:
toto@toto-K45VD:~$ mkdir gitfolder
 
2初始化一个git仓库,命令是:
toto@toto-K45VD:~$cd gitfolder/
toto@toto-K45VD:~/gitfolder$ls
toto@toto-K45VD:~/gitfolder$git init
初始化空的 Git版本库于 /home/toto/gitfolder/.git/
		
注意:如果是第一次使用git,还要对git对进行如下配置
git config --global user.email "yourEmail@qq.com"
git config --global user.name "tuzuoquan"
 
3 显示仓库内的所有内容,命令是:
toto@toto-K45VD:~/gitfolder$ll
总用量 12
drwxrwxr-x 3 toto toto 4096 1122 23:12 ./
drwxr-xr-x 31 toto toto 4096 1122 23:09 ../
drwxrwxr-x 7 toto toto 4096 1122 23:12 .git/
 
4 查看git仓库状态
toto@toto-K45VD:~/gitfolder$ git status
位于分支 master
初始提交
无文件要提交(创建/拷贝文件并使用"git add" 建立跟踪)
toto@toto-K45VD:~/gitfolder$
 
5 在仓库里面创建一个文件,并将这个文件添加到仓库中(注意也可以使用git add .将之添加到版本仓库中)
toto@toto-K45VD:~/gitfolder$ touch readme.txt
toto@toto-K45VD:~/gitfolder$ git status
位于分支 master
初始提交

未跟踪的文件:
  (使用 "git add <file>..." 以包含要提交的内容)
    readme.txt
提交为空,但是存在尚未跟踪的文件(使用
	"git	add" 建立跟踪)
toto@toto-K45VD:~/gitfolder$ls
readme.txt
 
6 将新建的文件添加到跟踪,命令如下:
toto@toto-K45VD:~/gitfolder$ git status
位于分支 master
初始提交
要提交的变更:
  (使用 "git rm --cached <file>..." 撤出暂存区)
	新文件:readme.txt

toto@toto-K45VD:~/gitfolder$
 
7readme.txt提交到git版本仓库,命令如下:
toto@toto-K45VD:~/gitfolder$git commit -m 'commit readme.txt'
[master(根提交) ad32b61]
commit readme.txt
 1  file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 readme.txt
toto@toto-K45VD:~/gitfolder$git status
位于分支 master
无文件要提交,干净的工作区
toto@toto-K45VD:~/gitfolder$
 
8查看当前分支信息,命令如下:
toto@toto-K45VD:~/gitfolder$git branch
*master
	
或者使用
git branch -a
 
9查看日志信息,命令如下:
toto@toto-K45VD:~/gitfolder$]git log
commit ad32b612b632ab62e6fe46630f3c6b03a1ff1ce3
Author: tuzuoquan <you@example.com>
Date:Sat Nov 22 23:31:12 2014 +0800

    commit readme.txt
toto@toto-K45VD:~/gitfolder$]git status
位于分支 master
无文件要提交,干净的工作区
toto@toto-K45VD:~/gitfolder$
 
10编辑readme.txt中的内容,并将之添加跟踪,并将之提交到版本仓库中去
readme.txt中的内容如下:
23:39 master readme.txt
			
查看git版本的状态,readme.txt添加到git.整个过程的命令如下:
toto@toto-K45VD:~/gitfolder$git status
位于分支 master
尚未暂存以备提交的变更:
  (使用 "git add <file>..." 更新要提交的内容)
  (使用 "git checkout -- <file>..." 丢弃工作区的改动)

	修改:readme.txt

修改尚未加入提交(使用 "git add" /"git commit -a"
toto@toto-K45VD:~/gitfolder$git add readme.txt 
toto@toto-K45VD:~/gitfolder$git status 
位于分支 master
要提交的变更:
  (使用 "git reset HEAD <file>..." 撤出暂存区)

	修改:readme.txt

toto@toto-K45VD:~/gitfolder$git add readme.txt
toto@toto-K45VD:~/gitfolder$git commit -m 'commited after modify'
[master b5c97f9] commited after modify
 1 file changed, 2 insertions(+)
 
11创建一个develop分支,查看所有的分支,命令如下:
toto@toto-K45VD:~/gitfolder$git branch develop

toto@toto-K45VD:~/gitfolder$git branch -a
  develop
*master
toto@toto-K45VD:~/gitfolder$
 
12查看git的日志信息
toto@toto-K45VD:~/gitfolder$git log
commit b5c97f9ad74458b1ec6a7fc38684305e45fff4de
Author:tuzuoquan <you@example.com>
Date:Sat Nov 22 23:49:49 2014 +0800

    commited after modify

commit ad32b612b632ab62e6fe46630f3c6b03a1ff1ce3
Author: tuzuoquan <you@example.com>
Date: Sat Nov 22 23:31:12 2014 +0800

    commit readme.txt
toto@toto-K45VD:~/gitfolder$
 
13切换到develop的分支,命令如下:
toto@toto-K45VD:~/gitfolder$git checkout develop
切换到分支 'develop'
toto@toto-K45VD:~/gitfolder$ls
readme.txt
toto@toto-K45VD:~/gitfolder$git branch
*develop
  master
toto@toto-K45VD:~/gitfolder$	
 
14创建2.txt,并将文件添加到对应的分支的版本仓库中.
toto@toto-K45VD:~/gitfolder$touch 2.txt
toto@toto-K45VD:~/gitfolder$ls
2.txt readme.txt
toto@toto-K45VD:~/gitfolder$git status
位于分支 develop
未跟踪的文件:
  (使用 "git add <file>..." 以包含要提交的内容)

	2.txt

提交为空,但是存在尚未跟踪的文件(使用"git add" 建立跟踪)
toto@toto-K45VD:~/gitfolder$vi 2.txt
 

14 切换到develop分支

toto@toto-K45VD:~/gitfolder$ git checkout develop

已经位于 'develop'

查看切换后的分支

toto@toto-K45VD:~/gitfolder$ git branch -a

* develop

  master

toto@toto-K45VD:~/gitfolder$ ls

2.txt  readme.txt

15 转换到master分支然后创建一个

toto@toto-K45VD:~/gitfolder$ git checkout master

切换到分支 'master'

创建一个分支develop2

toto@toto-K45VD:~/gitfolder$ git branch develop2

toto@toto-K45VD:~/gitfolder$ git checkout develop2

切换到分支 'develop2'

toto@toto-K45VD:~/gitfolder$ ls

2.txt  readme.txt

16 切换分支信息,并查看所在分支信息

toto@toto-K45VD:~/gitfolder$ git checkout develop

切换到分支 'develop'

toto@toto-K45VD:~/gitfolder$ git branch

* develop

  develop2

  master

toto@toto-K45VD:~/gitfolder$

toto@toto-K45VD:~/gitfolder$ git branch

* develop

  develop2

  master

toto@toto-K45VD:~/gitfolder$ ls

2.txt  readme.txt

对develop分支中的readme.txt文件中的内容进行修改

toto@toto-K45VD:~/gitfolder$ vi readme.txt

toto@toto-K45VD:~/gitfolder$ git status

位于分支 develop

尚未暂存以备提交的变更:

  (使用 "git add <file>..." 更新要提交的内容)

  (使用 "git checkout -- <file>..." 丢弃工作区的改动)

       修改:         readme.txt

未跟踪的文件:

  (使用 "git add <file>..." 以包含要提交的内容)

       .2.txt.swp

       2.txt

修改尚未加入提交(使用 "git add" 和/或 "git commit -a")

toto@toto-K45VD:~/gitfolder$

//将修改添加到分支

toto@toto-K45VD:~/gitfolder$ git add .

toto@toto-K45VD:~/gitfolder$ git commit -m 'xiugai'

[develop 722fbeb] xiugai

 3 files changed, 2 insertions(+)

 create mode 100644 .2.txt.swp

 create mode 100644 2.txt

17 切换分支到branch上,同时也修改develop分支中的文件readme.txt文件

toto@toto-K45VD:~/gitfolder$ git branch

* develop

  develop2

  master

toto@toto-K45VD:~/gitfolder$ git checkout develop2

切换到分支 'develop2'

toto@toto-K45VD:~/gitfolder$ ls

readme.txt

toto@toto-K45VD:~/gitfolder$ vi readme.txt

toto@toto-K45VD:~/gitfolder$ git status

位于分支 develop2

尚未暂存以备提交的变更:

  (使用 "git add <file>..." 更新要提交的内容)

  (使用 "git checkout -- <file>..." 丢弃工作区的改动)

       修改:         readme.txt

修改尚未加入提交(使用 "git add" 和/或 "git commit -a")

toto@toto-K45VD:~/gitfolder$ git commit -m 'develop2 commited after modified'

位于分支 develop2

尚未暂存以备提交的变更:

修改:         readme.txt

修改尚未加入提交

toto@toto-K45VD:~/gitfolder$ git add .

toto@toto-K45VD:~/gitfolder$ git commit -m 'develop2 commited after modified'

[develop2 8e8dc62] develop2 commited after modified

 1 file changed, 1 insertion(+)

toto@toto-K45VD:~/gitfolder$

18 先将develop合并到master,并解决合并冲突问题

toto@toto-K45VD:~/gitfolder$ git merge develop

自动合并 readme.txt

冲突(内容):合并冲突于 readme.txt

自动合并失败,修正冲突然后提交修正的结果。

toto@toto-K45VD:~/gitfolder$

冲突的内容如下:

23:39 master readme.txt

<<<<<<< HEAD

11 : 00

=======

08:47 修改

>>>>>>> develop

为了解决合并时出现的冲突,需要修改readme.txt中的内容,修改后的内容如下:

23:39 master readme.txt

08:47 修改

19 查看状态,并将修改正确后的文件提交到仓库中

toto@toto-K45VD:~/gitfolder$ git status

位于分支 develop2

您有尚未合并的路径。

   (解决冲突并运行 "git commit")

要提交的变更:

新文件:       .2.txt.swp

新文件:       2.txt

未合并的路径:

   (使用 "git add <file>..." 标记解决方案)

双方修改:     readme.txt

20 将修改后的所有内容添加到仓库中

toto@toto-K45VD:~/gitfolder$ git add .

toto@toto-K45VD:~/gitfolder$ git status

位于分支 develop2

所有冲突已解决但您仍处于合并中。

   (使用 "git commit" 结束合并)

    要提交的变更

新文件:       .2.txt.swp

新文件:       2.txt

修改:         readme.txt

toto@toto-K45VD:~/gitfolder$ git commit -m 'commit all'

[develop2 749fb3c] commit all

toto@toto-K45VD:~/gitfolder$

查看修改后的内容

toto@toto-K45VD:~/gitfolder$ cat readme.txt

23:39 master readme.txt

08:47 修改

toto@toto-K45VD:~/gitfolder$

 
相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
15天前
|
运维 应用服务中间件 nginx
docker运维查看指定应用log文件位置和名称
通过本文的方法,您可以更高效地管理和查看Docker容器中的日志文件,确保应用运行状态可控和可监测。
88 28
|
3月前
|
存储 Oracle 关系型数据库
【赵渝强老师】MySQL InnoDB的数据文件与重做日志文件
本文介绍了MySQL InnoDB存储引擎中的数据文件和重做日志文件。数据文件包括`.ibd`和`ibdata`文件,用于存放InnoDB数据和索引。重做日志文件(redo log)确保数据的可靠性和事务的持久性,其大小和路径可由相关参数配置。文章还提供了视频讲解和示例代码。
203 11
【赵渝强老师】MySQL InnoDB的数据文件与重做日志文件
|
2月前
|
存储 SQL 关系型数据库
【赵渝强老师】PostgreSQL的运行日志文件
PostgreSQL的物理存储结构包括数据文件、日志文件等。运行日志默认未开启,需配置`postgresql.conf`文件中的相关参数如`log_destination`、`log_directory`等,以记录数据库状态、错误信息等。示例配置中启用了CSV格式日志,便于管理和分析。通过创建表操作,可查看生成的日志文件,了解具体日志内容。
|
3月前
|
SQL 关系型数据库 MySQL
【赵渝强老师】MySQL的全量日志文件
MySQL全量日志记录所有操作的SQL语句,默认禁用。启用后,可通过`show variables like %general_log%检查状态,使用`set global general_log=ON`临时开启,执行查询并查看日志文件以追踪SQL执行详情。
|
3月前
|
Oracle 关系型数据库 数据库
【赵渝强老师】Oracle的参数文件与告警日志文件
本文介绍了Oracle数据库的参数文件和告警日志文件。参数文件分为初始化参数文件(PFile)和服务器端参数文件(SPFile),在数据库启动时读取并分配资源。告警日志文件记录了数据库的重要活动、错误和警告信息,帮助诊断问题。文中还提供了相关视频讲解和示例代码。
108 1
|
3月前
|
开发工具 git
git 常用命令
这些只是 Git 命令的一部分,Git 还有许多其他命令和选项,可根据具体需求进行深入学习和使用。熟练掌握这些命令能够帮助你更高效地管理代码版本和协作开发。
|
28天前
|
网络安全 开发工具 git
mac git clone命令提示git@gitee.com: Permission denied (publickey).问题修复
mac git clone命令拉取gitee上项目代码时提示密钥问题
|
27天前
|
Java 网络安全 开发工具
Git进阶笔记系列(01)Git核心架构原理 | 常用命令实战集合
通过本文,读者可以深入了解Git的核心概念和实际操作技巧,提升版本管理能力。
|
2月前
|
机器学习/深度学习 Shell 网络安全
【Git】Git 命令参考手册
Git 命令参考手册的扩展部分,包含了从基础操作到高级功能的全面讲解。
74 3
|
3月前
|
缓存 Java Shell
[Git]入门及其常用命令
本文介绍了 Git 的基本概念和常用命令,包括配置、分支管理、日志查看、版本回退等。特别讲解了如何部分拉取代码、暂存代码、删除日志等特殊需求的操作。通过实例和图解,帮助读者更好地理解和使用 Git。文章强调了 Git 的细节和注意事项,适合初学者和有一定基础的开发者参考。
75 1
[Git]入门及其常用命令