#--#--#(hash_B)--#--#---\ Branch B
/ \
---#---#---#---#(hash_A)---#---#---#---#---------------* Branch A
I want to push commmits from hash_A to hash_B. How can I do it without exposing any other commits? And keep the local scenario the same as before?
答案 0 :(得分:0)
Create a branch (I named it b1
below) on the hash_B
commit and push it to the remote server:
git branch b1 hash_B
git push origin b1
It is not possible to push only the commits from hash_A
to hash_B
. The entire history of hash_A
must also be present on the remote repository (it will be sent by git push
if it is not already there).
If the remote repository is empty, I think it is possible to achieve the result you want (I didn't test it).
Create another local repository as a shallow clone of the local repository, setting the hash_A
commit as the maximum depth it clones and hash_B
as its current branch.
Assuming your local repo is named local_repo1
, cd
to its parent directory and run:
git clone --shallow-exclude=hash_A~1 --branch=hash_B local_repo1 local_repo2
Then add the remote repository as a remote of local_repo2
and push
cd local_repo2
git remote set-url origin remote_repo_url
git push origin hash_B
(The command above doesn't add a new remote but changes the URL of the origin
remote. The effect is the same.)