简体   繁体   中英

Merge master from one repository to the master of another repository in one commit

What is the best way to accomplish this with git?

I am creating a private repository and want to be able to merge changes from another public repository periodically. However, in order to keep my private repository commit history clean, I don't want to bring in all the commits from the public repo, but be able to resolve any and all changes in just one commit.

Example of what I'm trying to do:

I initialize a repository on my server, myrepo.git

git init --bare

I clone this locally,

git clone user@server:myrepo.git

and proceed to make an initial commit on the master branch.

I then modify my git config, such that I add the the public repository as a new remote

[remote "origin"]
        url = user@server:myrepo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[remote "public"]
        url = http://github.com/path/to/publicrepo.git
        fetch = +refs/heads/*:refs/remotes/origin/*

Doing a git merge -X recursive -s ours public/master would make sense to me for what I am trying to accomplish, but I get the following:

(master) $ git merge -X recursive -s ours public/master
merge: public/master - not something we can merge

However, if I perform git pull public master , it will proceed to pull every commit from the public repo into the master on myrepo , ending with:

commit 421b15b37efacb84be80b95c8534087e67835017
Merge: be1a905 831a27d
Author: Me
Date:   Sun Feb 23 23:04:29 2014 -0500

Merge branch 'master' of http://github.com/path/to/publicrepo into master

This public repo has a great many commits and it is simply not feasible to squash them.

If possible I want to see one commit of Merge branch 'master' of http://github.com/path/to/publicrepo into master in the commit history of master on myrepo every time I resolve merge conflicts against public in myrepo .

Is it possible to do it this way, or is there a simpler way?

I am creating a private repository and want to be able to merge changes from another public repository periodically.

That's fine, but it's fundamentally incompatible with this:

However, in order to keep my private repository commit history clean, I don't want to bring in all the commits from the public repo, but be able to resolve any and all changes in just one commit.

You can't have a single commit which introduces all the change from the second repo, and still be able to periodically merge in changes. Git needs the commit IDs to match in order to know what is merged and what isn't, and doing this in one big merged commit guarantees that you will have no commit IDs in common with the public repo.

Merging requires that Git be able to rewind to the point where your two branches diverged. This can't happen if your branches never descend from a single parent, which is what it sounds like you're trying to set up. Just accept that you're going to have to include the entire history of commits from the public repo. I'm not even sure why you'd consider this undesirable, this is how Git is meant to work.

You could do this externally to git with simple patches, but again, I'm really not sure why you'd want to. You'll easily be able to see which commits are authored by you and which aren't, and if you ever hope to contribute anything back to the public repo, you'll need to have a shared history.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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