如何合并git中的特定文件 [英] how to merge specific files in git

查看:133
本文介绍了如何合并git中的特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在MASTER分支上有一个有100多个php文件的项目。为了在项目中修复bug,我创建了一个单独的分支

  git checkout -b bugfix 

然后在修复3个文件(例如index.php,register.php和login.php)中的bug后,我将它合并到master分支

  git checkout master 
git合并bugfix

上面的代码会合并我所做的更改的所有3个文件,但无论如何,我可以强制GIT合并仅2个文件,例如login.php和register .php only?

解决方案

以下解决方案来自一篇博文

事实证明,结账也可以在这件事情上有所帮助。您可以简单地从另一个分支调出(签出)这些特定文件:

 #切换到您想要成为合并目标的分支
git checkout master

#从特定分支签出特定文件
git checkout bugfix login.php register.php

#检查状态
git status

#将它们合并到
中git commit -m您的合并注释


Suppose I have a project on MASTER branch with 100s of php files. To do a bug fixing in the project, i create a separate branch

git checkout -b bugfix

Then after fixing the bug in 3 files (for eg index.php, register.php and login.php), i merge it in the master branch

git checkout master
git merge bugfix

The above code will merge all the 3 files i made changes, but is there anyway that i can force GIT to merge only 2 files, say login.php and register.php only?

解决方案

The following solution is adopted from a blog post

It turned out that checkout can also be helpful in this matter. You can simply callout (checkout) those specific files from another branch:

# switch to the branch you want to be your merge destination
git checkout master

# checkout specific files from specific branch
git checkout bugfix login.php register.php

# check the status
git status

# merge them in
git commit -m "your merge comment"

这篇关于如何合并git中的特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆