GIT分布式版本控制系统 命令讲解入门_cvi git

ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git status
On branch master	#当前本地库分支位置

No commits yet		#目前没有文件要提交

nothing to commit (create/copy files and use "git add" to track) 	#未提交,且无文件提交


ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        hello.txt

nothing added to commit but untracked files present (use "git add" to track)


添加暂存区——git add
git add 文件名
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git add hello.txt
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory


ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   hello.txt


文件删除暂存区——rm --cached
rm --cached 文件名
#删除暂存区,仍然存在工作区
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git rm --cached hello.txt
rm 'hello.txt'

提交本地库——git commit -m

将暂存区文件提交到本地库

git commit -m “日志信息” 文件名
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git commit -m "first commit" hello.txt
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory
[master (root-commit) 26da280] first commit
 1 file changed, 7 insertions(+)
 create mode 100644 hello.txt

ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git status
On branch master
nothing to commit, working tree clean


查看版本信息——git reflog
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git reflog
26da280 (HEAD -> master) HEAD@{0}: commit (initial): first commit
#版本号 版本

查看版本详细信息——git log
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git log
commit 26da28016adaee50fc76b4be71fbf2b4b3fda929 (HEAD -> master)
Author: weishuo <weishuo@weishuo.com>
Date:   Tue Apr 12 21:53:00 2022 +0800

    first commit


版本穿梭——git reset --hard 版本号
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git reset --hard ffce8cd
HEAD is now at ffce8cd second commit

ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git reflog
ffce8cd (HEAD -> master) HEAD@{0}: reset: moving to ffce8cd
534cbd3 HEAD@{1}: commit: third commit
ffce8cd (HEAD -> master) HEAD@{2}: commit: second commit
26da280 HEAD@{3}: commit (initial): first commit

分支的操作

命令名称作用
git branch 分支名创建分支
git branch -v查看当前分支
git checkout 分支名切换分支
git merge 分支名把指定的分支合并到当前分支上
查看当前分支——git branch -v
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git branch -v
* master 534cbd3 third commit


创建分支——git branch 分支名
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git branch hot-fix

ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git branch -v
  hot-fix 534cbd3 third commit
* master  534cbd3 third commit


切换分支——git checkout 分支名
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git checkout hot-fix
Switched to branch 'hot-fix'

ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (hot-fix)
$

ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (hot-fix)
$ git branch -v
* hot-fix 534cbd3 third commit
  master  534cbd3 third commit

合并分支——git merge 分支名
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git merge hot-fix
Updating 534cbd3..017517e
Fast-forward
 hello.txt | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)



合并分支(冲突合并)

检测有文件有两处修改

显示冲突
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git merge hot-fix
Auto-merging hello.txt
CONFLICT (content): Merge conflict in hello.txt
Automatic merge failed; fix conflicts and then commit the result.

ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master|MERGING)
$

ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master|MERGING)
$ git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   hello.txt

no changes added to commit (use "git add" and/or "git commit -a")



冲突合并
# 1.查看冲突代码
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master|MERGING)
$ vim hello.txt
# <<<< HEAD 当前分支代码
# <<<< HEAD 当前分支代码 =======
# ======= 合并分支代码 >>>>>>> hot-fix
#删除特殊符号 以及 重复代码

#2.添加到暂存区
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master|MERGING)
$ git add hello.txt

#3.提交本地库(不能带文件名)
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master|MERGING)
$ git commit -m "marge test"
fatal: cannot do a partial commit during a merge.

#4.切换分支查看
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master)
$ git checkout hot-fix
Switched to branch 'hot-fix'

#冲突合并,合并当前分支,不合并被合并分支
# head ---> master(分支内容)--->版本号
# HEAD决定当前分支

Git团队协作

在这里插入图片描述

在这里插入图片描述

命令名称作用
git remote -v查看当前所有进程地址别名
git remote add 别名 远程地址起别名
git push 别名 分支推送本地分支上的内容到远程仓库
git push 远程地址 分支推送本地分支上的内容到远程仓库
git clone 远程地址将远程仓库的内容克隆到本地
git pull 远程库地址别名 远程分支名将远程仓库对于分支最新内容拉下来后与当前本地分支直接合并
git push -f 远程库地址别名 远程分支名强制推送
创建远程库别名

git remote -v #查看当前所有进程地址别名
git remote add 别名 远程地址 #起别名

ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (hot-fix)
$ git remote -v

ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (hot-fix)
$ git remote add git.demo https://github.com/weishuoHH/git-demo.git

ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (hot-fix)
$ git remote -v
git.demo        https://github.com/weishuoHH/git-demo.git (fetch)
git.demo        https://github.com/weishuoHH/git-demo.git (push)


推送本地分支上的内容到远程仓库

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

推送本地分支上的内容到远程仓库

[外链图片转存中…(img-p5qgjksn-1714231077802)]
[外链图片转存中…(img-LHZhc4I6-1714231077802)]
[外链图片转存中…(img-q7W884fP-1714231077803)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

  • 24
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值