Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to re-merge a file in the git?

Tags:

git

git-merge

I have 10 files which have conflicts when merging branches. I've resolved all conflicts of the 10 files(took long time). Unfortunately before the commit, I find out that one file has been merged wrong and need start again for this file. :(

in the Git, How to mark the file which has been merged unmerged, in other word, how to re-merge that one file?

like image 367
Nyambaa Avatar asked Jun 22 '11 04:06

Nyambaa


People also ask

How do you redo a merge?

You can undo a Git merge using the git reset –merge command. This command changes all files that are different between your current repository and a particular commit. There is no “git undo merge” command but the git reset command works well to undo a merge.

How do I manually merge in git?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.


1 Answers

git checkout -m <filename> 

This will remove it from the index, and revert back to a "conflicted" file that has all of the markers required to then do a merge.

From the git help checkout man page:

-m, --merge     When switching branches, if you have local modifications to     one or more files that are different between the current     branch and the branch to which you are switching, the command     refuses to switch branches in order to preserve your     modifications in context. However, with this option, a     three-way merge between the current branch, your working tree     contents, and the new branch is done, and you will be on the     new branch.      When a merge conflict happens, the index entries for     conflicting paths are left unmerged, and you need to resolve     the conflicts and mark the resolved paths with git add (or git     rm if the merge should result in deletion of the path).      When checking out paths from the index, this option lets you     recreate the conflicted merge in the specified paths. 

(The last sentence is the most important one).

Here is a blog post that describes why it was added and how it is not possible with older versions of git: http://gitster.livejournal.com/43665.html

like image 121
X-Istence Avatar answered Oct 18 '22 12:10

X-Istence