首页 > 其他分享 >git merge 详细操作,看完就懂

git merge 详细操作,看完就懂

时间:2023-04-22 11:33:46浏览次数:39  
标签:git merge 详细 test commit main root change

[root@hostname git_test]# git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /root/git_test/.git/
[root@hostname git_test]# git log
fatal: your current branch 'master' does not have any commits yet
[root@hostname git_test]# vi test.txt
[root@hostname git_test]# git add .
[root@hostname git_test]# git commit "in main, 1st change"
error: pathspec 'in main, 1st change' did not match any file(s) known to git
[root@hostname git_test]# git commit -m "in main, 1st change"
[master (root-commit) 5c0420f] in main, 1st change
1 file changed, 1 insertion(+)
create mode 100644 test.txt
[root@hostname git_test]# git commit "in main, 1st change"^C
[root@hostname git_test]# vi test.txt
[root@hostname git_test]# git add .
[root@hostname git_test]# git commit -m "in main, 2nd change"
[master 16e9a53] in main, 2nd change
1 file changed, 1 insertion(+)
[root@hostname git_test]# gi tlog
bash: gi: command not found...
Similar command is: 'go'
[root@hostname git_test]# git log
commit 16e9a53302c804d3a0ad7924c45e00209c86c72f (HEAD -> master)
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:41:49 2023 -0400

in main, 2nd change

commit 5c0420f6c5efb9c8b98c89b9d4595f15c3fbed9c
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:41:23 2023 -0400

in main, 1st change
[root@hostname git_test]# git checkout -b feature_1
Switched to a new branch 'feature_1'
[root@hostname git_test]# vi test.txt
[root@hostname git_test]# git add .
[root@hostname git_test]# git commit -m "after branching, in feature_1, 1st change"
[feature_1 11981bf] after branching, in feature_1, 1st change
1 file changed, 1 insertion(+)
[root@hostname git_test]# git checkout master
Switched to branch 'master'
[root@hostname git_test]# vi test.txt
[root@hostname git_test]# git add .
[root@hostname git_test]# git commit -m "after branching, in main, 1st change"
[master 129c297] after branching, in main, 1st change
1 file changed, 1 insertion(+)
[root@hostname git_test]# vi test.txt
[root@hostname git_test]# git add .
[root@hostname git_test]# git commit -m "after branching, in main, 2nd change"
[master 87d7da3] after branching, in main, 2nd change
1 file changed, 1 insertion(+)
[root@hostname git_test]# git checkout feature_1
Switched to branch 'feature_1'
[root@hostname git_test]# vi test.txt
[root@hostname git_test]# git add .
[root@hostname git_test]# git commit -m "after branching, in feature_1, 2nd change"
[feature_1 c170207] after branching, in feature_1, 2nd change
1 file changed, 1 insertion(+)
[root@hostname git_test]# git log
commit c170207b0567946eff71880ee90326ad64822b0b (HEAD -> feature_1)
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:46:46 2023 -0400

after branching, in feature_1, 2nd change

commit 11981bffedb873679d73bdca89716f1b6cbc9f4d
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:42:58 2023 -0400

after branching, in feature_1, 1st change

commit 16e9a53302c804d3a0ad7924c45e00209c86c72f
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:41:49 2023 -0400

in main, 2nd change

commit 5c0420f6c5efb9c8b98c89b9d4595f15c3fbed9c
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:41:23 2023 -0400

in main, 1st change
[root@hostname git_test]# git checkout master
Switched to branch 'master'
[root@hostname git_test]# vi test.txt
[root@hostname git_test]# git add .
[root@hostname git_test]# git commit -m "after branching, in main, 3rd change"
[master 687068c] after branching, in main, 3rd change
1 file changed, 1 insertion(+)
[root@hostname git_test]# git log
commit 687068ce78e7f72326ecaec4c4d062139cd4d2c3 (HEAD -> master)
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:48:29 2023 -0400

after branching, in main, 3rd change

commit 87d7da3f4a51f811a846451bb75f7f8ccbd7cca0
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:44:23 2023 -0400

after branching, in main, 2nd change

commit 129c297f2ac32868f60a6cee4fc76970090648ab
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:43:46 2023 -0400

after branching, in main, 1st change

commit 16e9a53302c804d3a0ad7924c45e00209c86c72f
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:41:49 2023 -0400

in main, 2nd change

commit 5c0420f6c5efb9c8b98c89b9d4595f15c3fbed9c
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:41:23 2023 -0400

in main, 1st change
[root@hostname git_test]# git checkout feature_1
Switched to branch 'feature_1'
[root@hostname git_test]# git log
commit c170207b0567946eff71880ee90326ad64822b0b (HEAD -> feature_1)
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:46:46 2023 -0400

after branching, in feature_1, 2nd change

commit 11981bffedb873679d73bdca89716f1b6cbc9f4d
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:42:58 2023 -0400

after branching, in feature_1, 1st change

commit 16e9a53302c804d3a0ad7924c45e00209c86c72f
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:41:49 2023 -0400

in main, 2nd change

commit 5c0420f6c5efb9c8b98c89b9d4595f15c3fbed9c
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:41:23 2023 -0400

in main, 1st change
[root@hostname git_test]# git merge master
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.
[root@hostname git_test]# vi test.txt
[root@hostname git_test]# git status
On branch feature_1
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: test.txt

no changes added to commit (use "git add" and/or "git commit -a")
[root@hostname git_test]# git add .
[root@hostname git_test]# git commit -m "merge main, fix conflict"
[feature_1 ed8959d] merge main, fix conflict
[root@hostname git_test]# git log
commit ed8959dd5f7c200c9e45e69a1804ecb83b3cf89e (HEAD -> feature_1)
Merge: c170207 687068c
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:54:42 2023 -0400

merge main, fix conflict

commit 687068ce78e7f72326ecaec4c4d062139cd4d2c3 (master)
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:48:29 2023 -0400

after branching, in main, 3rd change

commit c170207b0567946eff71880ee90326ad64822b0b
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:46:46 2023 -0400

after branching, in feature_1, 2nd change

commit 87d7da3f4a51f811a846451bb75f7f8ccbd7cca0
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:44:23 2023 -0400

after branching, in main, 2nd change

commit 129c297f2ac32868f60a6cee4fc76970090648ab
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:43:46 2023 -0400

after branching, in main, 1st change

commit 11981bffedb873679d73bdca89716f1b6cbc9f4d
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:42:58 2023 -0400

after branching, in feature_1, 1st change

commit 16e9a53302c804d3a0ad7924c45e00209c86c72f
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:41:49 2023 -0400

in main, 2nd change

commit 5c0420f6c5efb9c8b98c89b9d4595f15c3fbed9c
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:41:23 2023 -0400

in main, 1st change


[root@hostname git_test]# git diff 11981bffedb873679d73bdca89716f1b6cbc9f4d 129c297f2ac32868f60a6cee4fc76970090648ab
diff --git a/test.txt b/test.txt
index 0681d7f..4e4c571 100644
--- a/test.txt
+++ b/test.txt
@@ -1,3 +1,3 @@
in main, 1st change
in main, 2nd change
-after branching, in feature_1, 1st change
+after branching, in main, 1st change


pick 11981bf after branching, in feature_1, 1st change
s c170207 after branching, in feature_1, 2nd change
pick 129c297 after branching, in main, 1st change
pick 87d7da3 after branching, in main, 2nd change
pick 687068c after branching, in main, 3rd change

# Rebase 16e9a53..ed8959d onto 16e9a53 (5 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.


Conflict:
[root@hostname git_test]# vi test.txt
in main, 1st change
in main, 2nd change
<<<<<<< HEAD
after branching, in feature_1, 1st change
after branching, in feature_1, 2nd change
=======
after branching, in main, 1st change
>>>>>>> 129c297 (after branching, in main, 1st change)


[root@hostname git_test]# git diff 11981bffedb873679d73bdca89716f1b6cbc9f4d 129c297f2ac32868f60a6cee4fc76970090648ab
diff --git a/test.txt b/test.txt
index 0681d7f..4e4c571 100644
--- a/test.txt
+++ b/test.txt
@@ -1,3 +1,3 @@
in main, 1st change
in main, 2nd change
-after branching, in feature_1, 1st change
+after branching, in main, 1st change
[root@hostname git_test]# git rebase -i 16e9a53302c804d3a0ad7924c45e00209c86c72f
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
error: could not apply 129c297... after branching, in main, 1st change
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 129c297... after branching, in main, 1st change
[root@hostname git_test]# git rebase --abort
[root@hostname git_test]# git rebase -i 16e9a53302c804d3a0ad7924c45e00209c86c72f
[detached HEAD d2b1d01] after branching, in feature_1, 1st change
Date: Fri Apr 21 22:42:58 2023 -0400
1 file changed, 2 insertions(+)
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
error: could not apply 129c297... after branching, in main, 1st change
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 129c297... after branching, in main, 1st change
[root@hostname git_test]# vi test.txt
[root@hostname git_test]# git add .
[root@hostname git_test]# git rebase --continue
[detached HEAD d1ac649] after branching, in main, 1st change
1 file changed, 1 insertion(+)
Successfully rebased and updated refs/heads/feature_1.
[root@hostname git_test]# git log
commit 4c6b9d68e4312a61e36f4bb95cad64f080d11d13 (HEAD -> feature_1)
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:48:29 2023 -0400

after branching, in main, 3rd change

commit fb2d8d2de1a02a1c3d930ec68f20ea6955cd6f8a
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:44:23 2023 -0400

after branching, in main, 2nd change

commit d1ac6493ba37454002009bf92a83363220a68e09
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:43:46 2023 -0400

after branching, in main, 1st change

commit d2b1d01d56705e26cc23a819c23e7a3d48c38104
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:42:58 2023 -0400

after branching, in feature_1, 1st change

after branching, in feature_1, 2nd change

commit 16e9a53302c804d3a0ad7924c45e00209c86c72f
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:41:49 2023 -0400

in main, 2nd change

commit 5c0420f6c5efb9c8b98c89b9d4595f15c3fbed9c
Author: Shuai Ma <[email protected]>
Date: Fri Apr 21 22:41:23 2023 -0400

in main, 1st change
[root@hostname git_test]# git diff 16e9a53302c804d3a0ad7924c45e00209c86c72f d2b1d01d56705e26cc23a819c23e7a3d48c38104
diff --git a/test.txt b/test.txt
index ff7d9a6..0a69e58 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,4 @@
in main, 1st change
in main, 2nd change
+after branching, in feature_1, 1st change
+after branching, in feature_1, 2nd change
[root@hostname git_test]# git diff d2b1d01d56705e26cc23a819c23e7a3d48c38104 d1ac6493ba37454002009bf92a83363220a68e09
diff --git a/test.txt b/test.txt
index 0a69e58..3469806 100644
--- a/test.txt
+++ b/test.txt
@@ -2,3 +2,4 @@ in main, 1st change
in main, 2nd change
after branching, in feature_1, 1st change
after branching, in feature_1, 2nd change
+after branching, in main, 1st change
[root@hostname git_test]#

 

 

 

标签:git,merge,详细,test,commit,main,root,change
From: https://www.cnblogs.com/mashuai-191/p/17342684.html

相关文章

  • git一个空分支
    如果不想要当前创建的分支拥有创建节点之前的内容,就需要一个完全为空的分支,可以参考知乎这篇文章,但是里面在删除所有文件那里命令在我的电脑上会提示fatal:Nopathspecwasgiven.WhichfilesshouldIremove?,后来把命令更换为gitrm*-f-r就可以了......
  • Vulnhub之HF 2019靶机详细测试过程
    HF2019作者:jasonhuawen靶机信息名称:HackerFest:2019地址:https://www.vulnhub.com/entry/hacker-fest-2019,378/识别目标主机IP地址将虚拟机镜像导入到VirtualBox中,并设置网络模式为host-only,然后启动KaliLinux以及目标主机(虚拟机):(kali㉿kali)-[~/Vulnhub/HF2019]......
  • git熟悉
    上传主要代码:gitinitgitadd.gitcommit-m"firstcommit"gitremoteaddorigin地址gitpush-uoriginmaster(第一次提交)gitpushoriginmaster(修改提交)SSL报错  unabletogetlocalissuercertificate 解决:gitconfig--globalhttp.sslverifyfalse......
  • git 代王座下最niu项目
    案例: http://118.31.34.207/#/login  oahttp://boss.wenkor.com/#/login  票务http://www.ttdianbao.com/#/login  配电https://www.datacloudfin.cn/#/login 数据的分析http://122.112.225.164:8000/#/login  省级考核https://dmswechattest.cslbehringshanghaicons......
  • git拉取指定目录或者单个目录
    1,目录初始化gitinit2,设置远程仓库地址gitremoteadd-foriginhttps://github.com/xxxxx3,设置sparsecheckout模式,允许克隆子目录gitconfigcore.sparsecheckouttrue4,设置指定拉取的目录(*是通配符,!是反选;例如xxx/*表示clients目录下所有)echoxxx/xxx......
  • Git
    1.简介开源的分布式版本控制系统,也是个内容管理系统(CMS),工作管理系统2.安装2.1InstallationunderUbuntu$sudoaptupdate$sudoapt-getinstallgit$git--version2.2Git提供了一个叫做gitconfig的工具,专门用来配置或读取相应的工作环境变量。/etc/gitco......
  • Linux系统文件加密的详细教程
    Linux系统一切皆为文件而且Linux系统又是一个多用户系统,所以数据的安全性非常重要,有些情况需要对文件进行加密,那么Linux系统中如何对文件进行加密呢?下面良许教程网为大家分享一下Linux系统文件加密的方法。方法一:gzexe加密 这种加密方式不是非常保险的方法,但是能够满足一般的加......
  • 基于Docker的GitLab更改克隆地址问题
    解决gitlab容器上的项目进行clone时,IP地址显示一串数字而不是正常IP地址的问题问题背景通过gitlab容器创建了一个项目,想clone到本地,结果发现项目的IP地址是一串数字 问题排查明明创建项目的时候,IP地址还是正常的鸭! 再看看项目的settings 那到底要......
  • 【汇智学堂】Git使用入门之二
    现在,让我们在项目下创建一个新的README文件。如果之前并不存在这个文件,使用gitstatus命令,你将看到一个新的未跟踪文件:在状态报告中可以看到新建的README文件出现在Untrackedfiles下面。未跟踪的文件意味着Git在之前的快照(提交)中没有这些文件;Git不会自动将之纳入跟......
  • GitLab 配置优化
    代码库最近换了,使用了GitLab。这两天观察了下服务器的使用情况,发现GitLab很吃内存。直接占用了30多个G的内存。一、发现问题使用top命令查看内存时,发现前几十个都是同一个应用程序。再通过ll/proc/pid命令查找具体程序位置,发现都是GItLab。这其中包含......