简体   繁体   English

重做git merge

[英]Redo a git merge

I have a remote master branch and a local called "feature". 我有一个远程主分支和一个本地的“功能”。 I have merged in from master before and did multiple changes on the local branch. 我之前是从master合并的,并且在本地分支上做了多次更改。 I haven't pushed it back up to master though. 我还没有把它推回去掌握。 So when I try to "git pull", it only says "Everything is up-to-date". 因此,当我尝试“ git pull”时,它只会显示“一切都是最新的”。 On the other hand the files in "master" and the files in "feature" are different, and I want to get rid of several files locally that we have, but master doesn't. 另一方面,“ master”中的文件和“ feature”中的文件是不同的,我想从本地删除一些我们拥有的文件,但master没有。 What I need is a way to pull master again and flag up every file as a conflict, so I can choose what I need and what I don't. 我需要的是一种再次拉动master并将每个文件标记为冲突的方法,因此我可以选择所需的内容和不需要的内容。 Rerolling the local changes is not an option as I would lose all my code I implemented. 重新滚动本地更改不是一种选择,因为我会丢失所有实现的代码。 Thanks for the help! 谢谢您的帮助!

尝试使用git reset HEAD~1使git认为它是历史记录中的提交(如果master的更改跨越多个重叠的提交, git pull …改为1),然后进行git pull …

You need to make the distinction between branches ( master , feature , you merge and pull ), and remotes (required to pull , and related to the message Everything is up-to-date ). 您需要区分分支( masterfeaturemergepull )和remotes (需要pull ,并且与消息“ Everything is up-to-date )之间的区别。 It's not very clear what your situation is, where are you trying to pull from? 目前还不清楚您的处境如何,您打算从哪里pull And what branch? 还有什么分支?

As far as I understand, you have a history where everything in the branch master is already merged in the branch feature 据我了解,您有一个历史记录,其中分支master中的所有内容都已合并到分支feature

If you are running git pull while you have the branch feature checked out, git tries to fetch new commits from a remote repo, then merge them (if any) to feature . 如果您在签出分支feature同时运行git pull ,则git尝试从remote库中fetch新提交,然后将它们合并(如果有)到feature This assumes that feature has a remote tracking branch, but if the command is working at all (with no arguments), it probably has one. 这假定该feature具有一个远程跟踪分支,但是如果该命令完全起作用(不带参数),则它可能只有一个。

Since git pull says that feature is up-to-date, it seems that you have already pushed the branch feature to its remote tracking branch (to a remote repo). 由于git pull表示该feature是最新的,因此您似乎已经将分支feature推送到其远程跟踪分支(到远程仓库)。 You pull, it tells you nothing more happened. 你拉,它告诉你什么都没有发生。

On the other hand, you may mean that master is up-to-date. 另一方面,您可能意味着master是最新的。

If you want to "get rid of several files locally that we have" (in feature , I suppose), then what stops you from just deleting them? 如果您想“本地删除我们拥有的几个文件”(在feature ,我想),那么是什么阻止您删除它们呢? git rm <file to get ridden of> . git rm <file to get ridden of> Do that while on feature , and you won't affect master . 在启用feature执行此操作,不会影响master Commit as you normally would. 像往常一样提交。

If you have changes in feature that you want to discard, and get the files as they are in master, you can git checkout master -- <file to get> . 如果您要放弃的feature发生了变化,并获得了它们在master中的文件,则可以git checkout master -- <file to get> This updates your local file to its master state, but without changing branch, you are still on feature . 这会将您的本地文件更新到其master状态,但是在不更改分支的情况下,您仍然处于feature Create new commits with these updated files, on feature . 创建具有这些更新的文件新的提交,就feature

What you also can do is an interactive rebase. 您还可以做的是交互式变基。 git rebase records the changes in feature and lets you "replay" them on top of another (or the same) commit. git rebase记录feature的更改,并允许您在另一个(或相同)提交之上“重播”它们。 In addition to that, git rebase --interactive lets you skip commits in the replay phase, and even edit what a commit does before replaying it. 除此之外, git rebase --interactive允许您在重播阶段跳过提交,甚至在重播之前编辑提交的内容。 For example, you could modify a commit in the replay phase, not to add the unnecessary files. 例如,您可以在重播阶段修改提交,而不添加不必要的文件。

Simplest would be the git checkout master -- <file> , if just removing the unnecessary files does not work. 如果仅删除不需要的文件不起作用,最简单的方法就是git checkout master -- <file>

Thank you all for your answers! 谢谢大家的答案! What I have ended up doing is: 1. checked out master 2. physically copy every folder master has into a different location 3. checked out feature 4. start a folder compare with "beyond compare" and one by one edited each files sometimes taking feature's changes, sometimes master's. 我最终要做的是:1.签出母版2.物理上将每个文件夹复制到另一个位置3.签出功能4.使用“超越比较”启动文件夹比较,然后逐个编辑每个文件,有时功能的变化,有时是大师的变化。

This is not really a git solution, and took a while, but it worked :) 这不是一个真正的git解决方案,花了一段时间,但确实可行:)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM