Git:如何推动仅对某些文件进行更改? [英] Git: how to push changes made to only certain files?
问题描述
- 我可以使用cherry-pick来挑选某个提交到新的分支并合并该分支进入远程主服务器。
- 我可以使用rebase -i重新排序提交,我假设我可以重新排序,以便与所选文件相关的提交全部在前面,我可以只需将该列表中的最后一个提交按钮推入即可。
对于樱桃挑选,这有点令人困惑。我可以创建一个没有任何脏提交的新分支,并选择文件提交到该分支。但是如果文件已经存在于分支中,它总是会引发一个我必须手动修复的冲突,这并不理想。
对于rebase -i,从我读过的内容我需要一个交互式编辑器,我需要手动对提交进行重新排序,然后我可以执行一个git push origin,将所有内容应用于commit-SHA(重新排序)。总体而言,我认为rebase更接近我所需要的,但我找不到一种以编程方式实现它的简单方法。任何人都可以想出一些可以完成我的任务的git类比操作吗?
我想我找到了解决这个问题的方法: cherry-pick --strategy =递归-Xtheirs< commit-SHA>
。
指定' '在递归合并策略中的选项强制冲突自动解决干净利于合并版本。这将忽略所有冲突警告,但抓住提交中的任何内容。
我想现在我只想知道为什么樱桃挑选会在选择修改当前分支中现有文件的提交时产生冲突警告,即使只是添加一行。
I recently ran into a problem where I need to select a few files to push to remote branches with git. My specific use case here is there is only one file created/modified in every single commit, and I need to programatically push the selected files (in their latest state). I did a bit of research and found 2 tricks that came close to what I need to do:
- I can use cherry-pick to pick certain commits into a new branch and merge that branch into the remote master.
- I can use rebase -i to reorder the commits, I assume I can reorder so that the commits relating to those selected files are all in front and I can just push the last commit in that list.
For cherry-pick it is a bit confusing. I can create a new branch without all the dirty commits and pick the file commits into that branch. However if the file already exists in the branch, it always throws a conflict that I have to fix manually, not ideal.
For rebase -i, from what I have read I need to goto an interactive editor where I need to manually reorder the commits, and after that I can do a git push origin to apply everything up to the commit-SHA (which is reordered). Not ideal since I have to do manual work.
Overall I think rebase came closer to what I need, but I couldn't find an easy way to do it programatically. Can anyone come up with some git analogy operations that can accomplish my task?
I think I have found the solution to this problem: cherry-pick --strategy=recursive -Xtheirs <commit-SHA>
.
Specifying the 'theirs' option in recursive merge strategy forces conflicts to auto-resolve cleanly favoring the version that's being merged in. This will ignore all the conflict warning but grab whatever is in the commit.
I guess now I just want to know why cherry-pick would produce a conflict warning when picking a commit that modified an existing file in the current branch, even if just adding a line.
这篇关于Git:如何推动仅对某些文件进行更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!