git branch & checkout fetch 的使用和冲突解决

时间:2023-03-08 16:44:47

git branch & checkout fetch 的使用和冲突解决

branch

git branch    查看本地分支

git branch -v     查看本地分支的具体信息(commit id,例如:f65ded9 和 commit 信息)

git branch -r   查看远程分支

git branch -a     查看本地和远程分支

git branch -vv         查看本地分支和远程分支的对应关系

git branch <new-branch-name>          新建本地分支

git branch <new-branch-name> <commit id>     给 commit id 新建一个分支

git branch -d <branch-name> [<branch-name>]     删除(多个)本地分支

checkout & branch

git checkout <branch-name>  切换到另外的一个分支

fetch & branch

git fetch origin master:<name-branch-name>  抓取远程仓库 origin 的 master 分支到本地的一个新分支<name-branch-name>

git diff <branch-name>             查看分支<branch-name>和当前分支的差异

git merge <branch-name>          融合分支<branch-name>到当前分支

merger冲突

如果当前分支和 merge 的分支有冲突(修改了同一个文件),而且当前分支没有 commit 过,就会提示先 commit,再 merge,这时候 merge 会提示那些冲突的文件自动合并失败,并让我们手动修复后在 commit 一次,在冲突的文件中会有类似以下内容:

<<<<<<< HEAD:index.html
<div id="footer">contact : email.support@github.com</div>
=======
<div id="footer">
please contact us at support@github.com
</div>
>>>>>>> iss53:index.html

修改后:

git add -A

git commit -m 'fix confliction'

git push