~~PAGEIMAGE:tools:git:tips:230512:media:20231129-235532.png~~
====== Push only one specified commit ======
{{template>meta:template:pageinfo#tpl
|desc=Introduces how to push only one specified commit and not the previous ones.}}
===== Steps =====
* Run git log %%--%%oneline to list the commit (''push-cmt'') to be pushed and the SHA (''rmt-head-sha'') of the ''HEAD'' (''rmt-head'') of the remote repository.
* Run git rebase -i rmt-head-sha to re-order the ''push-cmt'' to follow the ''rmt-head''.
* Run git log %%--%%oneline to get the SHA (''push-cmt-sha'') of the commit (''push-cmt'') to be pushed.
* Run git push remotename push-cmt-sha:remotebranchname.
===== Demo =====
This demo shows how to push only ''d0c2846'' at line 2 to the remote repository.
The statement following ''#'' is comment.
git log --oneline
d0c2846 (HEAD -> main) commit to be pushed #push-cmt
ff46af9 interference commit
04e4ff6 (origin/main, origin/HEAD) Make some adjustments #rmt-head, rmt-head-sha=04e4ff6
git rebase -i 04e4ff6
Successfully rebased and updated refs/heads/main.
git log --oneline
f2aaa65 (HEAD -> main) interference commit
85e4d6b commit to be pushed #push-cmt, push-cmt-sha=85e4d6b
04e4ff6 (origin/main, origin/HEAD) Make some adjustments #rmt-head
git push origin 85e4d6b:main
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 271 bytes | 271.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:siyuanl96/linux-jcd.git
04e4ff6..85e4d6b 85e4d6b -> main
git log --oneline
f2aaa65 (HEAD -> main) interference commit
85e4d6b (origin/main, origin/HEAD) commit to be pushed
04e4ff6 Make some adjustments
==== Gitgraph Evolutionary====
Before Rebase
%%{init: {'theme': 'base'} }%%
gitGraph TB:
checkout main
commit id: "04e4ff6" tag: "rmt-head"
branch local
checkout local
commit id:"ff46af9" tag: "interference commit"
commit id:"d0c2846" tag: "push-cmt" type: HIGHLIGHT
After Rebase
%%{init: {'theme': 'base'} }%%
gitGraph TB:
checkout main
commit id: "04e4ff6" tag: "rmt-head"
branch local
checkout local
commit id: "85e4d6b" tag: "push-cmt" type: HIGHLIGHT
commit id: "f2aaa65" tag: "interference commit"
Push ''85e4d6b''
%%{init: {'theme': 'base'} }%%
gitGraph TB:
checkout main
commit id: "04e4ff6" tag: "rmt-head"
branch local
checkout local
commit id:"85e4d6b" tag: "push-cmt" type: HIGHLIGHT
checkout main
merge local
checkout local
commit id:"f2aaa65" tag: "interference commit"
After Push
%%{init: {'theme': 'base'} }%%
gitGraph TB:
checkout main
commit id: "04e4ff6" tag: "rmt-head"
commit id:"85e4d6b" tag: "push-cmt" type: HIGHLIGHT
branch local
commit id:"f2aaa65" tag: "interference commit"
===== Further Reading =====
* //[[https://stackoverflow.com/questions/3230074/how-can-i-push-a-specific-commit-to-a-remote-and-not-previous-commits]]//