Git分支合并

常用命令

git branch# 列出本地分支
git branch -r# 列出远程分支
git branch -a# 列出both
git branch name# 创建新的本地分支
git branch -d name# 删除指定本地分支

# 本地分支重命名
git branch -m oldName newName
# 切换到hhx分支[切换HEAD指向]
git checkout hhx

# Merge branch 'dev' into feat_comparative_search
将dev合并至feat_comparative_search

# 在本地建立一个分支, 追踪指定的远程分支
git checkout -b newBranch origin/originBranch

# `git fetch origin` fetches any new work that has been pushed to that server since you cloned (or last fetched from) it.
# It`s important to note that the `git fetch` command only downloads the data to your local repository.
# it doesn’t automatically merge it with any of your work or modify what you’re currently working on.
# You have to merge it manually into your work when you’re ready.
git fetch

# To create a new branch and switch to it at the same time
# 相当于git branch newBranchName 加上 git checkout newBranchName
git checkout -b newBranchName

在这里插入图片描述
.git/HEAD 文件的内容是 当前所在的分支,随着分支切换,文件内容会动态发生变化
.git/refs/heads 文件夹中是 本地的所有分支,分支文件的内容是各自指向的 commit 的 hash值
HEAD指针永远指向当前所在的分支
切换分支,Git 会用该分支的最后提交的快照,替换工作区的内容

三方合并

git checkout master
git merge iss53 # 将iss53合并到master中

In this case,Git does a simple three-way merge,using the two snapshots pointed to by the branch tips and
the common ancestor of the two.

Git creates a new snapshot that results from this three-way merge and automatically creates a new commit that points to it.
This is referred to as a merge commit, and is special in that it has more than one parent.

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

合并冲突

# 合并冲突
If you changed the same part of the same file differently in the two branches you’re merging,Git won’t be
able to merge them cleanly.
It has paused the process while you resolve the conflict.

1.git status找到冲突文件
2.打开那个文件,进行修改,解决冲突
3.git add
4.git commit
A分支合并到B分支中,这时A分支代码是incoming change,(当前所在分支)B分支是current change

.gitignore

有些文件无需纳入 Git 的管理,也不希望它们总出现在未跟踪(Untracked)文件列表。
创建一个名为 .gitignore 的文件
文件 .gitignore 的格式规范:

使用 # 进行注释
/.idea/		忽略根目录下的.idea目录
*.iml		忽略所有iml文件
* 匹配零个或多个任意字符
[abc] 匹配任何一个列在方括号中的字符(这个例子要么匹配一个a,要么匹配一个b,要么匹配一个c)
? 只匹配一个任意字符

Git:合并分支
Git 分支
Git 分支讲解
git简单使用
git - 简易指南
日常工作中常用git命令小结
.gitignore语法说明
.gitignore语法
.gitignore文件语法
git合并远程分支
AutoMergeFailed,FixConflictsAndThenCommitTheResult
git修改分支名称

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Git分支合并是将两个或多个分支的更改合并到一起的过程。它允许团队员在不同的分支上独立开发功能,并将它们的更改合并到主分支或其他稳定分支中。 下面是一种常见的Git分支合并流程: 1. 首先,确保你在本地仓库中的主分支(通常是`master`或`main`分支)上进行操作。可以使用`git checkout master`命令切换到主分支。 2. 使用`git pull`命令更新本地主分支,以确保与远程仓库同步。 3. 创建一个新的分支来进行开发工作。可以使用`git branch <branch-name>`命令创建一个新分支,并使用`git checkout <branch-name>`命令切换到该分支。 4. 在新分支上进行开发工作,进行代码修改、添加新功能等。 5. 提交你的更改到新分支上。使用`git add <file-name>`命令将更改的文件添加到暂存区,然后使用`git commit -m "Commit message"`命令提交更改。 6. 在开发完成后,切换回主分支。使用`git checkout master`命令切换回主分支。 7. 使用`git pull`命令再次更新主分支,以确保与最新的远程代码同步。 8. 将新分支合并到主分支上。使用`git merge <branch-name>`命令将新分支的更改合并到主分支。在此过程中,Git会尝试自动合并更改,但有时可能会发生冲突。如果发生冲突,需要手动解决冲突。 9. 解决冲突后,使用`git add <file-name>`命令将解决冲突的文件标记为已解决。 10. 最后,使用`git commit -m "Merge branch"`命令提交合并结果。 这样,你就完成了分支合并。可以使用`git push`命令将更改推送到远程仓库,使其他团队成员可以访问到这些更改。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值