git使用步骤

下一篇:idea+Maven+Git使用步骤


  1. 下载

  2. 安装

  3. 使用
    在这里插入图片描述

  4. 创建GitHub账户

  5. 在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  6. cmd到你要上传的文件路径下面

  7. git init初始化,会生成.git文件

在这里插入图片描述
8. add和commit
在这里插入图片描述

  1. 设置用户名和密码和邮箱
    ,第一次登录要填写密码
Microsoft Windows [版本 10.0.22000.613]
(c) Microsoft Corporation。保留所有权利。

C:\Users\deqi5>cd c://

c:\>cd MyLearningFiles

c:\MyLearningFiles>cd repo1

c:\MyLearningFiles\repo1>git init
Initialized empty Git repository in C:/MyLearningFiles/repo1/.git/

c:\MyLearningFiles\repo1>git config --global user.name = "deqi-first"

c:\MyLearningFiles\repo1>git config --global user.email = "deqi525@outlook.com"

c:\MyLearningFiles\repo1>git add .

c:\MyLearningFiles\repo1>git commit -m "add test.txt"
[master (root-commit) e747611] add test.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test.txt

1. push

在这里插入图片描述

c:\MyLearningFiles\repo1>git remote add origin https://github.com/deqi-first/Java.git

c:\MyLearningFiles\repo1>git remote -v
origin  https://github.com/deqi-first/Java.git (fetch)
origin  https://github.com/deqi-first/Java.git (push)

c:\MyLearningFiles\repo1>git push origin master
Microsoft Windows [版本 10.0.22000.613]
(c) Microsoft Corporation。保留所有权利。

C:\Users\deqi5>cd C://

C:\>cd MyLearningFiles

C:\MyLearningFiles>cd repo1

C:\MyLearningFiles\repo1>git add .

C:\MyLearningFiles\repo1>git commit -m "add test.txt"
On branch master
nothing to commit, working tree clean

C:\MyLearningFiles\repo1>git remote -v
origin  https://github.com/deqi-first/Java.git (fetch)
origin  https://github.com/deqi-first/Java.git (push)

C:\MyLearningFiles\repo1>git push origin master
To https://github.com/deqi-first/Java.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/deqi-first/Java.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 integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

C:\MyLearningFiles\repo1>git pull --rebase origin master
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), 390 bytes | 13.00 KiB/s, done.
From https://github.com/deqi-first/Java
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
Successfully rebased and updated refs/heads/master.

C:\MyLearningFiles\repo1>git push origin master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 249 bytes | 249.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/deqi-first/Java.git
   c7bdb93..7e1036d  master -> master

C:\MyLearningFiles\repo1>

2. pull

在这里插入图片描述

在这里插入图片描述

Microsoft Windows [版本 10.0.22000.613]
(c) Microsoft Corporation。保留所有权利。

H:\MyLearningFiles\秋招>git init
Initialized empty Git repository in H:/MyLearningFiles/秋招/.git/

H:\MyLearningFiles\秋招>git remote add origin https://github.com/deqi-first/Markdown-Resume-Template.git

H:\MyLearningFiles\秋招>git remote -v
origin  https://github.com/deqi-first/Markdown-Resume-Template.git (fetch)
origin  https://github.com/deqi-first/Markdown-Resume-Template.git (push)

H:\MyLearningFiles\秋招>git pull origin master
remote: Enumerating objects: 65, done.
remote: Counting objects: 100% (2/2), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 65 (delta 0), reused 0 (delta 0), pack-reused 63
Unpacking objects: 100% (65/65), 31.41 KiB | 32.00 KiB/s, done.
From https://github.com/deqi-first/Markdown-Resume-Template
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master

3. 查看分支

在这里插入图片描述

4. 创建分支

在这里插入图片描述

5. 切换分支

在这里插入图片描述
如图:把*号切换到dev分支前
在这里插入图片描述

6. 查看分支的所有提交点

  1. 先提交
    在这里插入图片描述
  2. 查看提交点

在这里插入图片描述
3. 切换主分支,再次查看提交点
在这里插入图片描述

7. 分支合并

在这里插入图片描述

7.1 只有dev分支有修改的合并:fast-forward

具体实现:
在这里插入图片描述

7.2 dev和master分支都有修改的合并:三方合并

例题:
在这里插入图片描述
合并以上分支:
在这里插入图片描述
具体实现:

  1. 先在master和dev分支上都做修改,然后都提交
    在这里插入图片描述
  2. 当前的状态是:要合并master和dev上的修改,合并成的一个新的结点,要同时有master分支上的修改,也要有dev分支上的修改
    在这里插入图片描述

3. 分支合并的冲突解决

在这里插入图片描述

  1. 两个分支都对同一个文件有修改,合并后会出现冲突
    在这里插入图片描述
  2. 两个分支对同一个文件的修改,两种修改都会保留,你只需要,删除其中一个,然后重新提交就行
    在这里插入图片描述
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

素心如月桠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值