常用命令
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修改分支名称