简体   繁体   English

如何仅将过去分支中的更改文件合并到GIT中的主文件中?

[英]How to merged only changed files from a past branch into the master in GIT?

Say I create a local branch named fix_5109 and work on it. 假设我创建了一个名为fix_5109的本地分支,并对其进行处理。 In the meantime the master branch changes and some files which I'm NOT editing are normally changed(eg. /controllers/AuthController.php). 在此期间,master分支发生了变化,而一些我不编辑的文件通常也发生了变化(例如/controllers/AuthController.php)。 If I push my changes to origin fix_5109 the lead developer wants to merge my branch into the master if all went alright. 如果我将更改推送到原点fix_5109上,那么如果一切顺利,首席开发人员想将我的分支合并到master中。 My branch contains the old AuthController.php from an older commit behind master's newer. 我的分支包含来自master的较新版本之后的较旧提交的旧AuthController.php。 Will the file in the master branch be overwritten by my version of the file or would it reject my version of that file and update only the files I've edited in the branch I've pushed? master分支中的文件会被我的文件版本覆盖还是会拒绝该文件的版本并仅更新我在推送的分支中编辑的文件?

git functions in a way where if a commit is already applied, it won't be applied again (Uniqueness by commit hash). git作用方式是,如果已经应用了提交,则不会再次应用(通过提交哈希唯一性)。 So for your case, assuming you had diverged from master at some point in time when the changes to AuthController.php had already been made, then you don't have to worry. 因此,对于您的情况,假设您已经在对AuthController.php进行更改的某个时间与主服务器背道而驰,那么您不必担心。 Since, git would not replay a existing commit. 由于git不会重播现有的提交。

So even if your lead merges changes from your branch. 因此,即使您的潜在客户合并,分支机构也会发生变化。 He will basically have the latest code. 他基本上将拥有最新的代码。 ie) what ever change was last made (without diverging). 即)最后所做的更改(无差异)。 If the changes were made separately, then git would try to resolve the commits and apply them one after the other. 如果更改是分开进行的,则git会尝试解析提交,然后一次又一次地应用它们。 In this case, if there is a conflict then you would need to handle it explicitly. 在这种情况下,如果存在冲突,则需要显式处理。

git checkout master
git pull origin master
git checkout fix_5109
git rebase master

Basically rebasing your branch with the current state of master will take care of the issue you are concerned about. 从根本上以分支机构的当前状态重新分支您的分支机构将解决您担心的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当另一个分支合并到一个分支中时,如何查找更改的文件(忽略合并分支中的更改)? - How to find the files changed in one branch when another has been merged into it (ignoring changes from the merged branch)? 如何从git导出所有分支更改的文件与本地主文件相比 - how to export all branch changed files compared to local master from git 如何将文件从合并到其他 git 分支? - how to except files from be merged to other git branch? 如何从Git的master分支中排除特定合并分支的提交? - How to exclude a specific merged branch's commit from the master branch in Git? 如果合并或重新设置了主删除分支文件中的主Git`revert` - Git `revert` in master deleting branch files if merged or rebased 为什么 Git 只将一个分支部分合并到 master 中? - Why has Git only partially merged a branch into the master? 从合并的主分支恢复 git 个文件 - recover git files from merged master branches 我在git的错误分支上创建了一个分支,并将旧分支合并到master中,如何从另一个分支中删除提交? - I created a branch off of the wrong branch in git and already merged the old branch into master, how do I remove the commits from the other branch? Git:如何将过去的提交从主分支更改为其他分支? - Git : How can change past commit from master branch to other branch? Git:如何理解'git branch -a --merged master'列表 - Git: How to understand the 'git branch -a --merged master' listing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM