让我们说我有一个像sampath-test
这样的git分支。我从master repo
创建了这个分支。我创建了另一个新的存储库(master
),如ionic3-refactored
。这个新的master
存储库只有一个自述文件。那么你能告诉我如何将sampath-test
代码合并到新的master
回购ionic3-refactored
?
答案 0 :(得分:0)
您可以使用git push
执行此操作。
git push <path to repository> <local branch name>:<remote branch name>
这是一个例子。
首先,这是源存储库。 master
分支有几个文件,branch1
分支有一个附加文件:
$ git branch
branch1
* master
$ ls
file1.txt file2.txt README
$ git log | grep -v Author
commit 56cd34350e846b92762d16af1c777ff4075fff3e
Date: Sun Jun 10 01:02:23 2018 -0700
Add file1.txt and file2.txt
commit c5d453a847d3b61b75f8a27de3b3cdc163421398
Date: Sun Jun 10 01:01:55 2018 -0700
Add README
$ git checkout branch1
Switched to branch 'branch1'
$ ls
file1.txt file2.txt file3.txt README
$ git log | grep -v Author
commit bbdbd16488f835ee9bd0903274e45d18b0e621a1
Date: Sun Jun 10 01:02:53 2018 -0700
Add file3.txt
commit 56cd34350e846b92762d16af1c777ff4075fff3e
Date: Sun Jun 10 01:02:23 2018 -0700
Add file1.txt and file2.txt
commit c5d453a847d3b61b75f8a27de3b3cdc163421398
Date: Sun Jun 10 01:01:55 2018 -0700
Add README
这里创建了一个新的存储库并将newbranch
与其历史一起推送到其中:
$ mkdir ../newrepo
$ cd ../newrepo/
$ git init
Initialized empty Git repository in /home/chuckx/code/stackoverflow/gitpush/newrepo/.git/
$ cd ../repo1/
$ git push ../newrepo/ branch1:newbranch1
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (7/7), 596 bytes | 596.00 KiB/s, done.
Total 7 (delta 1), reused 0 (delta 0)
To ../newrepo/
* [new branch] branch1 -> newbranch1
$ cd ../newrepo/
$ git branch
newbranch1
$ ls
$ git checkout newbranch1
Switched to branch 'newbranch1'
$ ls
file1.txt file2.txt file3.txt README
$ git log | grep -v Author
commit bbdbd16488f835ee9bd0903274e45d18b0e621a1
Date: Sun Jun 10 01:02:53 2018 -0700
Add file3.txt
commit 56cd34350e846b92762d16af1c777ff4075fff3e
Date: Sun Jun 10 01:02:23 2018 -0700
Add file1.txt and file2.txt
commit c5d453a847d3b61b75f8a27de3b3cdc163421398
Date: Sun Jun 10 01:01:55 2018 -0700
Add README