git学习记录

本文详细介绍了在Ubuntu系统中安装并使用Git的基本步骤。包括如何通过终端安装Git,以及如何创建目录、初始化Git仓库、添加文件、查看状态、提交更改,并通过Git查看历史记录和操作文件。此外,还演示了如何使用命令行进行文件操作,如创建、修改、提交和撤销更改。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ubantu下

1 安装 

sudu apt-get install git

老版本可能需要使用sudo apt-get install git-core(因为老版本git是一个gnu的软件)

2 使用

1)创建一个目录(当做是一个项目的目录)

2)进入目录下,$git init 初始化git

新建一个文件作为例子,然后可以使用git查看文件是否被修改,修改内容。

3)

$touch file1 ,新建一个文件

$git add file1 ,将file1添加到git

$git status

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# new file:   file1
#
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)

终端显示,新添加文件file1

$ls > file1,将列表内容重定向到file1

$git add file1 ,再次将file1提交到git

$git diff file1

diff --git a/file1 b/file1
index e69de29..c2a115a 100644
--- a/file1
+++ b/file1
@@ -0,0 +1,3 @@
+file1

//+号后面就是刚刚重定义的内容

$git commit -m "add file name to file1"

可以提交“注释”,方便查看对于修改的解释

$git log file1 

Author: xxx    <xx@xx.com>
Date:   Wed Oct 8 19:50:44 2014 -0700

    add distribute

commit 0abd718832571200b8c56f9f169ada151b846603
Author: admin <870360524@qq.com>
Date:   Wed Oct 8 19:35:41 2014 -0700

    add file1 to project

显示“注释内容”

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值