目录

Git

讲解

1. 注册gitee账号

2.创建私人的库

3.  将git库内容克隆至Linux本地目录

4.三板斧

<1>三板斧第一招 : git add

<*>git status

<2> 三板斧第二招: git commit

<3>三板斧第三招: git push


Git

什么是git?为什么要上传至git?

日常生活中,我们如果要保存一个文档,往往直接就扔在桌面上了,会进行分类的朋友或许还会单独创建一个文件夹来存放那个文档。但是如果某一天,我需要找到这个文档的某一次修改前的内容,可能就很难找到。

而在未来的工作中,公司通常都是合作形式来完成工作,这时候不仅仅是你一个人的工作,一个文档或者文件可能会被好几个同事进行修改,这个时候,如果我们用微信之类的软件反复传递文件,不仅耗时间,还很有可能找不到最后这个文件的修改版本,更严重的,如果文件出现了问题,很难去溯源这个问题是谁导致的,是谁修改了这个文件。

于是,便有了git,很好的解决了这一系列的问题。

它可以同时保存你文件修改前后的各个版本,可以同时被你组里的同事随时看到,最重要的,它会保存所有的修改属性,包括 XXX在2023.XX.XX时候对这个文件进行了怎样的修改,并且它强制要求修改人写下日志来帮助我们检阅。

此处,我们举用国内的gitee进行详细的讲解如何从Linux上传至我们的git库.

讲解

1. 注册gitee账号

60b5d11cfec640dea22c703f7c245002.png

一定要记住你的用户名和密码,后面进行克隆和上传都需要你的用户名和密码。

2.创建私人的库

f286799ae242458e81b1085993de7f93.png

 依照上图进行仓库创建

1c3c67be221344198160f2f5c51704e5.png

因为我们是给自己的程序进行上传,所以不需要添加开源许可证。

模版设置为Redme文件。

创建完成后,可以进入仓库查看

721aa9fbbc78430c890819cfb3fe3deb.png

里面有三个文件,分别为.gitignore,README.en.md,README.md,这些是git的配置文件,非必要不要随意修改。

3.  将git库内容克隆至Linux本地目录

[fengjunzi@VM-4-2-centos test]$ mkdir test  
[fengjunzi@VM-4-2-centos test]$ cd test
[fengjunzi@VM-4-2-centos test]$ ll
total 0
在你的目录创建一个新的文件夹

0541bb7fa25043a9b9263af05073204e.png

 在我们的gitee库里我们可以看到   克隆/下载,有https协议的克隆链接,我们点击复制。

接下来我们在Linux中输入指令  git clone (刚刚复制的链接)

[fengjunzi@VM-4-2-centos test]$ git clone (刚刚复制的链接)
Cloning into 'test-for-write'...
Username for 'https://gitee.com': (输入你的Gitee用户名)
Password for 'https://@gitee.com': (输入你的Gitee密码)
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), done.

如果你输入指令没有错误,但是报错了,可能是你的Linux 系统没有安装git命令

输入  sudo yum -y install git    来进行安装git命令

sudo yum -y install git

 接下来,我们就可以看到你的空文件夹中多了一个文件夹,并且那个文件夹的名字与我们刚刚创建的库的名字一样,我们cd进去可以看到里面有我们在库里看到的所有文件(注意:.git配置文件不要修改,不然会出现难以预料的错误)。

[fengjunzi@VM-4-2-centos test]$ ll
total 4
drwxrwxr-x 3 fengjunzi fengjunzi 4096 Apr 26 16:52 test-for-write
[fengjunzi@VM-4-2-centos test]$ cd test-for-write/
[fengjunzi@VM-4-2-centos test-for-write]$ ll
total 8
-rw-rw-r-- 1 fengjunzi fengjunzi 826 Apr 26 16:52 README.en.md
-rw-rw-r-- 1 fengjunzi fengjunzi 915 Apr 26 16:52 README.md
[fengjunzi@VM-4-2-centos test-for-write]$ ll -a
total 24
drwxrwxr-x 3 fengjunzi fengjunzi 4096 Apr 26 16:52 .
drwxrwxr-x 3 fengjunzi fengjunzi 4096 Apr 26 16:52 ..
drwxrwxr-x 8 fengjunzi fengjunzi 4096 Apr 26 16:52 .git
-rw-rw-r-- 1 fengjunzi fengjunzi  270 Apr 26 16:52 .gitignore
-rw-rw-r-- 1 fengjunzi fengjunzi  826 Apr 26 16:52 README.en.md
-rw-rw-r-- 1 fengjunzi fengjunzi  915 Apr 26 16:52 README.md

4.三板斧

<1>三板斧第一招 : git add

git add [文件名] 

作用:将需要用 git 管理的文件告知 git

首先将我们需要上传的文件或文件夹拷贝一份到我们刚刚克隆的目录中

[fengjunzi@VM-4-2-centos lesson6]$ cp -rf progressBar ../test/test-for-write   //复制文件
[fengjunzi@VM-4-2-centos lesson6]$ cd ..
[fengjunzi@VM-4-2-centos test]$ cd test
[fengjunzi@VM-4-2-centos test]$ ll
total 8 
drwxrwxr-x 2 fengjunzi fengjunzi 4096 Apr 26 19:10 progressBar   //刚刚复制过来的文件
-rw-rw-r-- 1 fengjunzi fengjunzi  828 Apr 26 18:56 README.en.md
-rw-rw-r-- 1 fengjunzi fengjunzi  917 Apr 26 18:56 README.md
[fengjunzi@VM-4-2-centos test]$ 

再使用  git add [文件名]       将我们想要上传的文件添加入我们刚刚下载克隆文件夹之中

[fengjunzi@VM-4-2-centos test]$ git add progressBar
[fengjunzi@VM-4-2-centos test]$ 

告知完毕并不代表我们的已经提交了文件,更不代表已经和gitee库同步,还有后续操作

<*>git status

git status

作用:反应git目前的状态,并提示你下一步的指令

[fengjunzi@VM-4-2-centos test]$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   progressBar/Makefile
#	new file:   progressBar/test
#	new file:   progressBar/test.c
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	test-for-write/

比如说现在,我们刚刚输入了  git add 指令  ,再输入git status 他会提示我们或许要使用git rm --cached<file>来撤销我们刚刚的add指令,这里我们不撤销。

<2> 三板斧第二招: git commit

git commit -m "你的日志信息"   //注意,这里的-m必须要添加,否则不会让你提交

此处输入 git commit 指令,必须要添加-m指令,否则无法通过提交,正是因为git的严密性,才深受企业和个人的喜爱使用,大大提升了安全性。

[fengjunzi@VM-4-2-centos test]$ git commit -m "progressBar程序已经完成测试"
[master (root-commit) 9e60f08] progressBar程序已经完成测试
 3 files changed, 25 insertions(+)
 create mode 100644 progressBar/Makefile
 create mode 100755 progressBar/test
 create mode 100644 progressBar/test.c

如果出现了如下报错,一般是因为你是第一次在这台设备上提交上传内容,只需要输入你的邮箱和姓名就可以了

***Please tell me who you are.



Run



git config --global user. email "you@example. com"
git config --global user. name "Your Name"

//如果出现了此报错,一般是因为你是第一次在这台设备上提交上传内容,只需要输入你的邮箱和姓名就可以了

<3>三板斧第三招: git push

git push

作用:将你的克隆库同步至你的gitee库

输入git push 后大功告成

[fengjunzi@VM-4-2-centos study-for-linux]$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 3.29 KiB | 0 bytes/s, done.
Total 6 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To git@gitee.com:fengjunziya/study-for-linux.git
   011bf70..87fc325  master -> master

进入我们的gitee库查看,上传同步完成 

a0e93f976c0546e6ada3b48962f92075.png

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐