git合并分支并提交

git合并分支并提交

git status
git add .
git commit -m "修改"
git push 分支名
git checkout '需要切换的分支名'
git pull
git merge '需要合并的子分支'
git push '主分支'
git checkout '子分支'
git pull origin '主分支'

冲突

1.git合并的时候,冲突问题Merging is not possible because you have unmerged files
在做项目工作的时候,同事修改了代码一个A代码,我同样也修改了代码,两人代码冲突了,提交之后,他代码git自动合并,并提示: [master| MERGEING]

$ git merge my_new_branch
error: Merging is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
又或者提示如下错误:
Auto-merging src/ui/menu/wizardGroup.c
Auto-merging src/ui/menu/drawmenu5.c
Auto-merging src/ui/menu/drawmenu3.c
Auto-merging src/ui/menu/drawmenu2.c
Auto-merging src/ui/menu/drawmenu1.c
Auto-merging src/ui/menu/drawmenu0.c
Auto-merging src/string/language_d.h
CONFLICT (content): Merge conflict in src/string/language_d.h
Auto-merging src/string/languageDict.h
CONFLICT (content): Merge conflict in src/string/languageDict.h
Auto-merging src/drawui.c
Auto-merging src/dev/dev_phascan.c
Auto-merging src/dev/dev_flexscan.c
Auto-merging src/callback.c
Automatic merge failed; fix conflicts and then commit the result.

解决方法:
If you have fixed the conflicts you need to add the files to the stage with git add [filename], then commit as normal.
就是你手动修改git提示有错误的文件,修改之后,添加有冲突的文件: git add [被修改的冲突文件], 最后,按照普通提交那样,提交有冲突的问题: git commit [修改后的冲突文件] -m “注释内容”

*简单的来说就是:
用git diff或者git status 查看哪些文件冲突,有冲突的会提示:
++<<<<<<< HEAD
++<<<<<<< new_branch
修改你的冲突的文件,修改完之后,保存。
用git add xxx,把你修改的文件全部都添加进去。
最后,用git commit -a -m ” 备注信息 ” 提交,完成。

【git】如何去解决fatal: refusing to merge unrelated histories

我在Github新建一个仓库,写了License,然后把本地一个写了很久仓库上传。
先pull,因为两个仓库不同,发现refusing to merge unrelated histories,无法pull
因为他们是两个不同的项目,要把两个不同的项目合并,git需要添加一句代码,在git pull,
这句代码是在git 2.9.2版本发生的,最新的版本需要添加--allow-unrelated-histories

git pull origin master --allow-unrelated-histories
git reflog //查看版本
git reset --hard //版本回退
posted @ 2021-01-06 15:02  背锅侠-渣渣关😩  阅读(205)  评论(0)    收藏  举报