文章目录
-
下载
-
安装
-
使用
-
创建GitHub账户
-
-
cmd到你要上传的文件路径下面
-
git init初始化,会生成.git文件
8. add和commit
- 设置用户名和密码和邮箱
,第一次登录要填写密码
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. 查看分支的所有提交点
- 先提交
- 查看提交点
3. 切换主分支,再次查看提交点
7. 分支合并
7.1 只有dev分支有修改的合并:fast-forward
具体实现:
7.2 dev和master分支都有修改的合并:三方合并
例题:
合并以上分支:
具体实现:
- 先在master和dev分支上都做修改,然后都提交
- 当前的状态是:要合并master和dev上的修改,合并成的一个新的结点,要同时有master分支上的修改,也要有dev分支上的修改
3. 分支合并的冲突解决
- 两个分支都对同一个文件有修改,合并后会出现冲突
- 两个分支对同一个文件的修改,两种修改都会保留,你只需要,删除其中一个,然后重新提交就行