EzDevInfo.com

merge interview questions

Top merge frequently asked interview questions

How to merge a specific commit in git

I have forked a branch from a repository in GitHub and commit something specific to me. Now I found the original repository has a good feature which is at HEAD.

I want to merge it only without previous commits, what I should do? I have known how to merge all commit:

git branch -b a-good-feature
git pull repository master
git checkout master
git merge a-good-feature
git commit -a
git push

Source: (StackOverflow)

How to undo a git merge with conflicts

I am on branch mybranch1. mybranch2 is forked from mybranch1 and changes were made in mybranch2.

Then, while on mybranch1, I have done git merge --no-commit mybranch2 It shows there were conflicts while merging.

Now I want do discard everything (the merge command) so that mybranch1 is back to what it was before. I have no idea how do I go about this.


Source: (StackOverflow)

Advertisements

How do you merge two git repositories?

Consider the following scenario: I have developed small experimental project A in its own git repo. It has now matured, and I'd like A to be part of larger project B, which has its own big repository. I'd now like to add A as a subdirectory of B.

How do I merge A into B, without losing history on any side?


Source: (StackOverflow)

Simple tool to 'accept theirs' or 'accept mine' on a whole file using git

I don't want a visual merge tool, and I also don't want to have to vi the conflicted file and manually choose the between HEAD (mine) and the imported change (theirs). Most of the time I either want all of their changes or all of mine. Commonly this is because my change made it upsteam and is coming back to me through a pull, but may be slightly modified in various places.

Is there a command line tool which will get rid of the conflict markers and choose all one way or another based on my choice? Or a set of git commands which I can alias myself to do each one.

# accept mine
alias am="some_sequence;of;commands"
alias at="some_other_sequence;of;commands"

Doing this is rather annoying. For 'accept mine' I have tried:

randy@sabotage ~/linus $ git merge test-branch
Auto-merging Makefile
CONFLICT (content): Merge conflict in Makefile
Automatic merge failed; fix conflicts and then commit the result.

randy@sabotage ~/linus $ git checkout Makefile 
error: path 'Makefile' is unmerged

andy@sabotage ~/linus $ git reset --hard HEAD Makefile 
fatal: Cannot do hard reset with paths.

How am I supposed to get rid of these change markers?

I can do:

git reset HEAD Makefile; rm Makefile; git checkout Makefile

But this seems rather round about, there must be a better way. And at this point, I'm not sure if git even thinks the merge happened, so I don't think this necessarily even works.

Going the other way, doing 'accept theirs' is equally messy. The only way I can figure it out is do:

git show test-branch:Makefile > Makefile; git add Makefile;

This also gives me a messed up commit message, which has Conflicts: Makefile in it twice.

Can someone please point out how to do the above two actions in a simpler way? Thanks


Source: (StackOverflow)

How do I copy a version of a single file from one git branch to another?

I've got two branches that are fully merged together.

However, after the merge is done, I realise that one file has been messed up by the merge (someone else did an auto-format, gah), and it would just be easier to change to the new version in the other branch, and then re-insert my one line change after bringing it over into my branch.

So what's the easiest way in git to do this?


Source: (StackOverflow)

JPA EntityManager: Why use persist() over merge()?

EntityManager.merge() can insert new objects and update existing ones.

Why would one want to use persist() (which can only create new objects)?


Source: (StackOverflow)

Oracle: how to UPSERT (update or insert into a table?)

The UPSERT operation either updates or inserts a row in a table, depending if the table already has a row that matches the data:

if table t has a row exists that has key X:
    update t set mystuff... where mykey=X
else
    insert into t mystuff...

Since Oracle doesn't have a specific UPSERT statement, what's the best way to do this?


Source: (StackOverflow)

Why am I getting tree conflicts in subversion?

I had a feature branch of my trunk and was merging changes from my trunk into my branch periodically and everything was working fine. Today I went to merge the branch back down into the trunk and any of the files that were added to my trunk after the creation of my branch were flagged as a "tree conflict". Is there any way to avoid this in the future? I don't think these are being properly flagged.

Thanks.


Source: (StackOverflow)

How do I create a readable diff of two spreadsheets using git diff?

We have a lot of spreadsheets (xls) in our source code repository. These are usually edited with gnumeric or openoffice.org, and are mostly used to populate databases for unit testing with dbUnit. There are no easy ways of doing diffs on xls files that I know of, and this makes merging extremely tedious and error prone.

I've tried to converting the spreadsheets to xml and doing a regular diff, but it really feels like it should be a last resort.

I'd like to perform the diffing (and merging) with git as I do with text files. How would I do this, e.g. when issuing git diff?


Source: (StackOverflow)

How to join multiple lines of file names into one with custom delimiter?

I would like to join the result of ls -1 into one line and delimit it with whatever i want.

Are there any standard Linux commands I can use to achieve this?


Source: (StackOverflow)

What's the best three-way merge tool? [closed]

Subversion, Git, Mercurial and others support three-way merges (combining mine, theirs, and the "base" revision) and support graphical tools to resolve conflicts.

What tool do you use? Windows, Mac OS X, Linux, free or commercial, you name it.

Here's a few that I've used or heard of, just to get the conversation started:

(I recognize that this is sort of like the Best Diff Tool, but it's different in that I explicitly focus on three-way merge tools; WinMerge is off the list, for example.)


Source: (StackOverflow)

What's the difference between 'git merge' and 'git rebase'?

I'm trying to understand ... What's the difference between git merge and git rebase?


Source: (StackOverflow)

How to correctly close a feature branch in Mercurial?

I've finished working on a feature branch feature-x. I want to merge results back to the default branch and close feature-x in order to get rid of it in the output of hg branches.

I came up with the following scenario, but it has some issues:

$ hg up default
$ hg merge feature-x
$ hg ci -m merge
$ hg up feature-x
$ hg ci -m 'Closed branch feature-x' --close-branch

So the feature-x branch (changests 40-41) is closed, but there is one new head, the closing branch changeset 44, that will be listed in hg heads every time:

$ hg log ...
o  44 Closed branch feature-x
|
| @  43 merge
|/|
| o  42 Changeset C
| |
o |  41 Changeset 2
| |
o |  40 Changeset 1
|/
o  39 Changeset B
|
o  38 Changeset A
|

Update: It appears that since version 1.5 Mercurial doesn't show heads of closed branches in the output of hg heads anymore.

Is it possible to close a merged branch without leaving one more head? Is there more correct way to close a feature branch?

Related questions:


Source: (StackOverflow)

Git Cherry-pick vs Merge Workflow

Assuming I am the maintainer of a repo, and I want to pull in changes from a contributor, there are a few possible workflows:

  1. I cherry-pick each commit from the remote (in order). In this case git records the commit as unrelated to the remote branch.
  2. I merge the branch, pulling in all changes, and adding a new "conflict" commit (if needed).
  3. I merge each commit from the remote branch individually (again in order), allowing conflicts to be recorded for each commit, instead of grouped all together as one.
  4. For completeness, you could do a rebase (same as cherry-pick option?), however my understanding is that this can cause confusion for the contributor. Maybe that eliminates option 1.

In both cases 2 and 3, git records the branch history of the commits, unlike 1.

What are the pro's and con's between using either cherry-pick or merge methods described? My understanding is that method 2 is the norm, but I feel that resolving a large commit with a single "conflict" merge, is not the cleanest solution.


Source: (StackOverflow)

How to import existing GIT repository into another?

I have a (Windows) GIT repository in a folder called XXX, and I have second GIT repository called YYY.

I want to import the XXX repository into the YYY repository, add all XXX's change history to YYY, and rename XXX to ZZZ.

Folder structure before:

XXX
 |- .git
 |-  ZZZ

Folder structure after:

YYY
 |- .git  <-- This now contains the change history from XXX
 |-  ZZZ  <-- This was originally XXX
 |-  (other folders)

Can this be done, or must I resort to using sub-modules?


Source: (StackOverflow)