前进才是唯一的方向
一、git是什么?
1.
Git是一个开源的分布式版本控制系统,可以有效、高速地处理从很小到非常大的项目版本管理。 也是Linus Torvalds雷纳斯托瓦兹为了帮助管理Linux内核开发而开发的一个开放源码的版本控制软件。
2.
说白了git就是一个进行项目版本管理的一个软件。
二、gitee仓库创建
1.新建仓库
1.在gitee的主界面右上角有新建仓库
2.对仓库进行信息配置
2.复制仓库链接
点击橙色按钮里的HTTPS链接进行仓库链接的复制
3.克隆远端仓库到本地来
git clone+仓库链接,就可以将远端仓库克隆到本地上
[wyn@VM-8-2-centos workdir]$ git clone https://gitee.com/raise-your-glass-to-the-moon/12_27fordebug.git Cloning into '12_27fordebug'... Username for 'https://gitee.com': 15598303669 Password for 'https://15598303669@gitee.com': remote: Enumerating objects: 6, done. remote: Counting objects: 100% (6/6), done. remote: Compressing objects: 100% (6/6), done. remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (6/6), done.
三、git提交代码
1.下载git
sudo yum -y install git
2. 配置用户名和邮箱(否则git commit无法正常使用)
1.下面是已经配置好的配置信息
git config --list // 查看git的配置列表
2.配置成全局,当前普通用户的所有本地仓库都有效,不仅仅是某个仓库。
git config --global user.name "username" // 名字缩写即可 git config --global user.email "email"// 正常使用的邮箱
3.修改你的配置信息
git config --replace-all user.name "new-name" git config --replace-all user.email "new-email"
4.查看git config的其他选项都有哪些功能
[wyn@VM-8-2-centos 12_27fordebug]$ git config usage: git config [options] Config file location --global use global config file --system use system config file --local use repository config file -f, --file <file> use given config file --blob <blob-id> read config from given blob object Action --get get value: name [value-regex] --get-all get all values: key [value-regex] --get-regexp get values for regexp: name-regex [value-regex] --replace-all replace all matching variables: name value [value_regex] --add add a new variable: name value --unset remove a variable: name [value-regex] --unset-all remove all matches: name [value-regex] --rename-section rename section: old-name new-name --remove-section remove a section: name -l, --list list all -e, --edit open an editor --get-color <slot> find the color configured: [default] --get-colorbool <slot> find the color setting: [stdout-is-tty] Type --bool value is "true" or "false" --int value is decimal number --bool-or-int value is --bool or --int --path value is a path (file or directory name) Other -z, --null terminate values with NUL byte --includes respect include directives on lookup
3. git提交代码三板斧
3.1 git add(将代码添加到本地仓库.git的临时区域)
利用*我们可以一次性将后缀为指定后缀的文件进行统一性的操作,例如下面我将所有后缀为.c和.h的文件统一剪切到process目录下面,然后我们就可以将当前目录添加到本地仓库.git的临时区域里面。
[wyn@VM-8-2-centos workdir]$ mv *.c process [wyn@VM-8-2-centos workdir]$ mv *.h process [wyn@VM-8-2-centos 12_27fordebug]$ git add .
3.2 git commit -m(将代码提交到本地仓库.git里面)
add是添加到仓库的临时区域,commit是提交到本地仓库里面
[wyn@VM-8-2-centos 12_27fordebug]$ ll total 24 -rw-rw-r-- 1 wyn wyn 9592 Dec 27 09:40 LICENSE drwxrwxr-x 2 wyn wyn 4096 Dec 27 10:04 process -rw-rw-r-- 1 wyn wyn 859 Dec 27 09:40 README.en.md -rw-rw-r-- 1 wyn wyn 948 Dec 27 09:40 README.md [wyn@VM-8-2-centos 12_27fordebug]$ git commit -m "这是第一次提交代码"
3.3 git push(同步本地仓库.git的内容到gitee上)
所谓的本地仓库,本质就是目录和目录里面的内容,这个目录名字叫.git,push到远端,本质就是将.git里面的内容同步到gitee上面,同步之后的gitee上其实也有一个.git的目录,只不过gitee是不允许我们看到这个目录的。
[wyn@VM-8-2-centos 12_27fordebug]$ git push Username for 'https://gitee.com': 15598303669 Password for 'https://15598303669@gitee.com': Counting objects: 7, done. Delta compression using up to 2 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (5/5), 584 bytes | 0 bytes/s, done. Total 5 (delta 2), reused 0 (delta 0) remote: Powered by GITEE.COM [GNK-6.4] To https://gitee.com/raise-your-glass-to-the-moon/12_27fordebug.git 0f71a6a..1f9b73a master -> master
四、其他扩展的git指令
1.文件.gitignore是什么?
凡是在这个文件内部的后缀所对应的文件,都不会被上传到gitee上!
[wyn@VM-8-2-centos 12_27fordebug]$ vim .gitignore 1 *.sln 添加了.sln后缀,作为.gitignore文件的改动 2 # Prerequisites 3 *.d 4 5 # Compiled Object files 6 *.slo 7 *.lo 8 *.o 9 *.obj 10 11 # Precompiled Headers 12 *.gch 13 *.pch 14 15 # Compiled Dynamic libraries 16 *.so 17 *.dylib 18 *.dll 19 20 # Fortran module files 21 *.mod 22 *.smod 23 24 # Compiled Static libraries 25 *.lai 26 *.la 27 *.a 28 *.lib 29 30 # Executables 31 *.exe 32 *.out 33 *.app
2 git log(查看git的提交日志)
[wyn@VM-8-2-centos process]$ git log commit 64e37f98443db1be25ee2a34a4cef39b24db8602 Author: wyn <wang.ya.nan2022@outlook.com> Date: Tue Dec 27 14:40:34 2022 +0800 删除.txt后缀的文件 commit 1e28723cf0ef7d6b1ce5887df56e25655bd11748 Author: wyn <wang.ya.nan2022@outlook.com> Date: Tue Dec 27 14:25:40 2022 +0800 rename file commit 02deaf907420261dc19fe61aba3acbf1ec422107 Author: wyn <wang.ya.nan2022@outlook.com> Date: Tue Dec 27 14:18:51 2022 +0800 修正了部分野指针的bug commit d46c141392ab63ca70cdf545feec3a287e9a0177 Author: wyn <wang.ya.nan2022@outlook.com> Date: Tue Dec 27 10:39:21 2022 +0800 这是我的第一次提交 commit 14b1e1e46acdda069e87fbadaf6c0b3177dbeb80 Author: 举杯邀明月 <wang.ya.nan2022@outlook.com> Date: Tue Dec 27 01:38:23 2022 +0000 Initial commit
3 git status(查看本地仓库的状态)
1.
第7行的modified内容表示我们刚刚修改过文件.gitignore的内容
第9行的Untracked代表未被管理的文件,这些文件是仓库中没有的文件
2.
当你同步完所有你在本地仓库的改动文件之后,系统会说没有什么commit了,因为你已经把最新的本地仓库的所有改动全部同步到远端仓库了
[wyn@VM-8-2-centos process]$ git status # On branch master # 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: ../.gitignore # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # Makefile # test.txt no changes added to commit (use "git add" and/or "git commit -a") [wyn@VM-8-2-centos 12_27fordebug]$ git status # On branch master nothing to commit, working directory clean
4 git mv + git rm(修改和删除本地仓库的文件)
[wyn@VM-8-2-centos process]$ git mv test.txt hello.txt [wyn@VM-8-2-centos process]$ git rm -f hello.txt
远端仓库全都已经最新同步了
5 git pull(拉取远端仓库所作的修改到本地仓库)
1.
首先我们需要知道,我们是可以在远端仓库进行修改的
2.
如果远端仓库已经做了修改,但是还没有同步到本地仓库,这个时候如果本地仓库想要继续push本地仓库所做的修改到远端,就会直接报错,系统会强制我们先同步远端仓库所作的修改
[wyn@VM-8-2-centos 12_27fordebug]$ git push Username for 'https://gitee.com': 15598303669 Password for 'https://15598303669@gitee.com': To https://gitee.com/raise-your-glass-to-the-moon/12_27fordebug.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://gitee.com/raise-your-glass-to-the-moon/12_27fordebug.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first merge the remote changes (e.g., hint: 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
3.
所有我们必须要同步远端仓库所做的修改到本地仓库
[wyn@VM-8-2-centos 12_27fordebug]$ git pull