2

新しい git リポジトリを開始したいのですが、外部のサードパーティのリポジトリのファイルを出発点として使用しています。

ブランチ マスターに空のリポジトリがあり、ファイルはありません。最初のコミットとしてファイルを追加したいのですが、別の git リポジトリからコピーする必要があります。

これを行うためのgitの方法はありますか、それともリポジトリをチェックアウトしてファイルをリポジトリにコピーする必要がありますか。

4

2 に答える 2

1

リモート リポジトリの履歴を保存したい場合は、次のようにします。

# Initialize your local repository
git init
# Add the source-repo where you want to pull the files from
git remote add source-repo <URL of Source repo>
# Make git fetch the history for the source-repo
git fetch source-repo

# Merge from BRANCH_NAME of source-repo into
# the current branch (which should be called master by default)
git merge source-repo/BRANCH_NAME

複数のコミットではなく、単一のコミットでファイルを追加 (つまり、マージ) したい場合は、squash-mergeを利用できます。現在 (2013 年 3 月) の時点で、gitは空のリポジトリでのスカッシュ マージをサポートしていません。そのため、このようなスカッシュ マージを行う前に、少なくとも 1 つのコミットが必要になります。

したがって、次のようなことができます。

# Initialize your local repository
git init
# Add the source-repo where you want to pull the files from
git remote add source-repo <URL of Source repo>
# Make git fetch the history for the source-repo
git fetch source-repo

# Create a dummyfile and commit the change
touch dummyfile
git add dummyfile
git commit -m "Dummy file change."

# Create a squash merge from BRANCH_NAME of source-repo into
# the current branch (which should be called master by default)
git merge --squash source-repo/BRANCH_NAME
于 2013-03-16T22:10:58.487 に答える
0

チェックアウトしてコピーする必要はありません。リモート リポジトリについて git に知らせるだけで、次のようにマージできます。

git remote add the-remote-repository <url of remote repo>
git remote update
git merge the-remote-repository/master   # or whatever branch you want to pull in
于 2013-03-16T21:59:54.510 に答える