5分钟知道git如何使用?(git入门常用命令)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了5分钟知道git如何使用?(git入门常用命令)相关的知识,希望对你有一定的参考价值。
参考技术A这里引用一下“菜鸟教程”对git的描述
Git 常用的是以下 6 个命令:git clone、git push、git add 、git commit、git checkout、git pull
关于git下载安装这里就不细说了,毕竟我们只有5分钟的时间,可以去git官网下载对应的版本网上查查安装教程。
首先建立一个本地仓库(repository)。你可以使用一个已经存在的目录作为Git仓库或创建一个空目录。我这里就创建一个空目录itep为例:
初始化本地仓库
我们有一个仓库,但什么也没有,先在工作区创建一个文件‘demo.html’,可以使用add命令添加到暂存区。
我们在工作区创建了好几个新的文件,html,js,和css。接下来我们都可以添加到暂存区
当我们修改了很多文件,而不想每一个都add,想commit自动来提交本地修改,我们可以使用-a标识。 注意是修改,而不是新增,新增的文件我们还是要先add,之后再修改这些文件的话,就可以直接使用-a命令了。
现在我们已经添加了这些文件,我们希望它们能够真正被保存在Git仓库。
为此,我们将它们提交到本地仓库
接下来我们发布版本,提交到远程仓库。注意这里远程仓库的地址只是举例
5分钟已经到了吧...
上面从新建一个页面,提交到远程仓库的流程已经说完了,接下来我们说点别的。。
删除文件
删除工作区和暂存区文件git rm ,删除文件有以下几种形式
对,就是这么简单,你的工作区和暂存区demo.js这个文件已经没有了
如果删除之前修改过并且已经放到暂存区域的话,则必须要用强制删除选项 -f。
强行从暂存区和工作区中删除修改后的 demo.html 文件:
如果想把文件从暂存区中删除,但仍然希望保留在当前工作目录中的话这样操作
Git - 入门到熟悉_日志管理
文章目录
Pre
在使用 Git 提交了若干更新之后,又或者克隆了某个项目,想回顾下提交历史,可以使用 git log 命令查看。
常用命令
#查看当前分支下所有提交日志
git log
#查看当前分支下所有提交日志
git log branch
# 单行显示日志
git log --oneline
# 比较两个版本的区别
git log master..experiment
#以图表的方式显示提交合并网络
git log --pretty=format:'%h %s' --graph
演示
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git log
commit 36a0f0253e4967e30dbcc7689eff872f72138444 (HEAD -> master, tag: tag_0816, origin2/master, origin/master)
Author: yangshangwei <yswcomeon@gmail.com>
Date: Tue Aug 16 05:18:54 2022 +0800
8 commit
commit b685db4861c9d8ba7a4f251f3aa26ebca8b7a271
Author: yangshangwei <yswcomeon@gmail.com>
Date: Tue Aug 16 04:57:25 2022 +0800
7 commit
commit 9f302ffcd77e703b02e9d185d085484f1e298c0a
Author: yangshangwei <yswcomeon@gmail.com>
Date: Mon Aug 15 00:34:03 2022 +0800
第四次提交
commit 2d23d8a4a8b9f79f893ce7ef594624929b57d31c (tag: 4_commit)
Author: yangshangwei <yswcomeon@gmail.com>
Date: Mon Aug 15 00:24:25 2022 +0800
第三次提交
commit 5e6d25b9e0f1bae23ce98facecf79ad4e97df174
Author: yangshangwei <yswcomeon@gmail.com>
Date: Sun Aug 14 23:55:34 2022 +0800
第二次提交
commit 4ac59bd9186592662350d23f1cdfbe5c4f21f329
Author: yangshangwei <yswcomeon@gmail.com>
Date: Sun Aug 14 23:02:58 2022 +0800
init commit
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git branch
* master
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git log master
commit 36a0f0253e4967e30dbcc7689eff872f72138444 (HEAD -> master, tag: tag_0816, origin2/master, origin/master)
Author: yangshangwei <yswcomeon@gmail.com>
Date: Tue Aug 16 05:18:54 2022 +0800
8 commit
commit b685db4861c9d8ba7a4f251f3aa26ebca8b7a271
Author: yangshangwei <yswcomeon@gmail.com>
Date: Tue Aug 16 04:57:25 2022 +0800
7 commit
commit 9f302ffcd77e703b02e9d185d085484f1e298c0a
Author: yangshangwei <yswcomeon@gmail.com>
Date: Mon Aug 15 00:34:03 2022 +0800
第四次提交
commit 2d23d8a4a8b9f79f893ce7ef594624929b57d31c (tag: 4_commit)
Author: yangshangwei <yswcomeon@gmail.com>
Date: Mon Aug 15 00:24:25 2022 +0800
第三次提交
commit 5e6d25b9e0f1bae23ce98facecf79ad4e97df174
Author: yangshangwei <yswcomeon@gmail.com>
Date: Sun Aug 14 23:55:34 2022 +0800
第二次提交
commit 4ac59bd9186592662350d23f1cdfbe5c4f21f329
Author: yangshangwei <yswcomeon@gmail.com>
Date: Sun Aug 14 23:02:58 2022 +0800
init commit
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git log --oneline
36a0f02 (HEAD -> master, tag: tag_0816, origin2/master, origin/master) 8 commit
b685db4 7 commit
9f302ff 第四次提交
2d23d8a (tag: 4_commit) 第三次提交
5e6d25b 第二次提交
4ac59bd init commit
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git log --pretty=format:'%h %s' --graph
* 36a0f02 8 commit
* b685db4 7 commit
* 9f302ff 第四次提交
* 2d23d8a 第三次提交
* 5e6d25b 第二次提交
* 4ac59bd init commit
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git branch dev
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git branch
dev
* master
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git checkout dev
Switched to branch 'dev'
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$ ls
README.MF src/
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$ echo 'devv' >README.MF
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$ git status
On branch dev
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.MF
no changes added to commit (use "git add" and/or "git commit -a")
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$ git add -A ;
warning: LF will be replaced by CRLF in README.MF.
The file will have its original line endings in your working directory
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$ git status
On branch dev
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: README.MF
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$ git commit -am 'dev firs commit';
[dev 188ec16] dev firs commit
1 file changed, 1 insertion(+), 1 deletion(-)
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$ git push ;
fatal: The current branch dev has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin dev
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$ git push --set-upstream origin dev
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 281 bytes | 281.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
remote: Create a pull request for 'dev' on Gitee by visiting:
remote: https://gitee.com/yangshangwei/gitProject/pull/new/yangshangwei:dev...yangshangwei:master
To https://gitee.com/yangshangwei/gitProject.git
* [new branch] dev -> dev
Branch 'dev' set up to track remote branch 'dev' from 'origin'.
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$ git log dev
commit 188ec1684503dcdea074fc27d2d2718065a83b4e (HEAD -> dev, origin/dev)
Author: yangshangwei <yswcomeon@gmail.com>
Date: Wed Aug 17 00:41:59 2022 +0800
dev firs commit
commit 36a0f0253e4967e30dbcc7689eff872f72138444 (tag: tag_0816, origin2/master, origin/master, master)
Author: yangshangwei <yswcomeon@gmail.com>
Date: Tue Aug 16 05:18:54 2022 +0800
8 commit
commit b685db4861c9d8ba7a4f251f3aa26ebca8b7a271
Author: yangshangwei <yswcomeon@gmail.com>
Date: Tue Aug 16 04:57:25 2022 +0800
7 commit
commit 9f302ffcd77e703b02e9d185d085484f1e298c0a
Author: yangshangwei <yswcomeon@gmail.com>
Date: Mon Aug 15 00:34:03 2022 +0800
第四次提交
commit 2d23d8a4a8b9f79f893ce7ef594624929b57d31c (tag: 4_commit)
Author: yangshangwei <yswcomeon@gmail.com>
Date: Mon Aug 15 00:24:25 2022 +0800
第三次提交
commit 5e6d25b9e0f1bae23ce98facecf79ad4e97df174
Author: yangshangwei <yswcomeon@gmail.com>
Date: Sun Aug 14 23:55:34 2022 +0800
第二次提交
commit 4ac59bd9186592662350d23f1cdfbe5c4f21f329
Author: yangshangwei <yswcomeon@gmail.com>
Date: Sun Aug 14 23:02:58 2022 +0800
init commit
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$ git log --pretty=format:'%h %s' --graph
* 188ec16 dev firs commit
* 36a0f02 8 commit
* b685db4 7 commit
* 9f302ff 第四次提交
* 2d23d8a 第三次提交
* 5e6d25b 第二次提交
* 4ac59bd init commit
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$ git log dev
commit 188ec1684503dcdea074fc27d2d2718065a83b4e (HEAD -> dev, origin/dev)
Author: yangshangwei <yswcomeon@gmail.com>
Date: Wed Aug 17 00:41:59 2022 +0800
dev firs commit
commit 36a0f0253e4967e30dbcc7689eff872f72138444 (tag: tag_0816, origin2/master, origin/master, master)
Author: yangshangwei <yswcomeon@gmail.com>
Date: Tue Aug 16 05:18:54 2022 +0800
8 commit
commit b685db4861c9d8ba7a4f251f3aa26ebca8b7a271
Author: yangshangwei <yswcomeon@gmail.com>
Date: Tue Aug 16 04:57:25 2022 +0800
7 commit
commit 9f302ffcd77e703b02e9d185d085484f1e298c0a
Author: yangshangwei <yswcomeon@gmail.com>
Date: Mon Aug 15 00:34:03 2022 +0800
第四次提交
commit 2d23d8a4a8b9f79f893ce7ef594624929b57d31c (tag: 4_commit)
Author: yangshangwei <yswcomeon@gmail.com>
Date: Mon Aug 15 00:24:25 2022 +0800
第三次提交
commit 5e6d25b9e0f1bae23ce98facecf79ad4e97df174
Author: yangshangwei <yswcomeon@gmail.com>
Date: Sun Aug 14 23:55:34 2022 +0800
第二次提交
commit 4ac59bd9186592662350d23f1cdfbe5c4f21f329
Author: yangshangwei <yswcomeon@gmail.com>
Date: Sun Aug 14 23:02:58 2022 +0800
init commit
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$ git log dev --oneline
188ec16 (HEAD -> dev, origin/dev) dev firs commit
36a0f02 (tag: tag_0816, origin2/master, origin/master, master) 8 commit
b685db4 7 commit
9f302ff 第四次提交
2d23d8a (tag: 4_commit) 第三次提交
5e6d25b 第二次提交
4ac59bd init commit
artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (dev)
$ git blame README.MF
188ec168 (yangshangwei 2022-08-17 00:41:59 +0800 1) devv
以上是关于5分钟知道git如何使用?(git入门常用命令)的主要内容,如果未能解决你的问题,请参考以下文章