There are two forks, yours and others. In the second at the beginning there are several commits I need, and then unnecessary ones. How can I see only the first n commits from another fork?
- oneEither you do not quite understand what a pull request is, or you described a little something that you really want to do .-. - D-side
- @ D-side, maybe explain what's wrong - sercxjo
- Pull request is a request to accept changes. And what you are describing is more like a partial acceptance of a pull request (if there was any such request). - D-side
- @ D-side Yes, it requires a partial acceptance, the re-request can be done by yourself with someone else's fork, but there is no choice of commit, as far as I noticed, the request is made on the HEAD of the specified branch of the specified fork. I 'll try your answer - sercxjo
4 answers
For starters, you should get PR to yourself in a local repository. If this does not happen automatically, this can be done by prescription in the help of Gitchab :
git fetch origin pull/{ID}/head You can also get someone else's branch locally completely, to work with it:
git fetch origin pull/{ID}/head:{local-branch} Then you can do as ixSci told you:
git merge {commit-SHA} git push Do not forget to also close the PR in the web interface so that it no longer hangs.
It's simple, find commit SHA that interests you, and, being in the branch you need, it does:
git merge <commit-SHA> This command will add all the changes that have occurred since your and other people's branches diverged, up to the necessary fixation (commit), the SHA-identifier of which you indicated.
- hmm, but this commit, to which I want to make a merge, is in another fork in a branch with the same name. - sercxjo
- @sercxjo This is absolutely not a problem. Did you read my answer? - D-side
- @sercxjo, the name of a branch in git is a convention, it has no meaning. - ixSci
If there are few commits, then the easiest way is to download them to a local repository for freedom of action:
git remote add ΡΠΎΡΠΊ URL_ΡΠΎΡΠΊΠ° git fetch ΡΠΎΡΠΊ ... and then I can offer two options:
Plain
Find the necessary SHA-hashes of the necessary commits in the branch log:
git log ΡΠΎΡΠΊ/Π²Π΅ΡΠΊΠ°cherry-pickby / SHA hashes in order of their use:git checkout Π»ΠΎΠΊΠ°Π»ΡΠ½Π°Ρ_Π²Π΅ΡΠΊΠ° git cherry-pick a1a1a1 b2b2b2 c3c3c3 # ^^^^^^ ^^^^^^ ^^^^^^ ΠΏΡΠ΅ΡΠΈΠΊΡΡ Ρ ΡΡΠ΅ΠΉ ΠΊΠΎΠΌΠΌΠΈΡΠΎΠ²There is nowhere to make a mistake here, but if you are nervous, you can do this beforehand:
git checkout -b Π½Π΅Π½ΡΠΆΠ½Π°Ρ_Π²Π΅ΡΠΊΠ° Π»ΠΎΠΊΠ°Π»ΡΠ½Π°Ρ_Π²Π΅ΡΠΊΠ°... and
cherry-pickinto it. When it will be what you (seemingly) need, send it to the main one, requesting "rewind" (extra insurance against unwanted effects):git checkout Π»ΠΎΠΊΠ°Π»ΡΠ½Π°Ρ_Π²Π΅ΡΠΊΠ° git merge --ff-only Π½Π΅Π½ΡΠΆΠ½Π°Ρ_Π²Π΅ΡΠΊΠ°Difficult (but can be more convenient)
Interactive rebase (
rebase -i) is good when much of their history is common, and the differences are easy to solve:# ΡΠ΄Π΅Π»Π°ΡΡ Π½Π° Π²Π΅ΡΠΊΠ΅ Ρ Π½ΡΠΆΠ½ΡΠΌΠΈ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡΠΌΠΈ Π½ΠΎΠ²ΡΡ Π²Π΅ΡΠΊΡ git checkout -b Π½ΠΎΠ²ΡΠ΅_ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ ΡΠΎΡΠΊ/Π²Π΅ΡΠΊΠ° # Π²ΡΡΠΈΡΠ»ΠΈΡΡ ΠΎΡΡΡΡΡΡΠ²ΡΡΡΠΈΠ΅ ΠΊΠΎΠΌΠΌΠΈΡΡ ΠΈ ΠΏΠ΅ΡΠ΅Π½Π΅ΡΡΠΈ Π²Π΅ΡΠΊΡ Π½Π° Π²Π΅ΡΡ ΡΡΠΊΡ Π»ΠΎΠΊΠ°Π»ΡΠ½Π°Ρ_Π²Π΅ΡΠΊΠ° git rebase -i Π»ΠΎΠΊΠ°Π»ΡΠ½Π°Ρ_Π²Π΅ΡΠΊΠ° Π½ΠΎΠ²ΡΠ΅_ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡThis displays a text editor with a list of
Π½ΠΎΠ²ΡΠ΅_ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡthat are in theΠ½ΠΎΠ²ΡΠ΅_ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ, but not in theΠ½ΠΎΠ²ΡΠ΅_ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ. Each line is one commit: the operation (it says what each of them does, by defaultpickthe same ascherry-pick), hash and description. After you close the editor, the designated section of theΠ½ΠΎΠ²ΡΠ΅_ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡbranch will be rewritten according to what you write in the editor.By removing the appropriate line, you remove the commit (from the
Π½ΠΎΠ²ΡΠ΅_ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ, but not from the originalΡΠΎΡΠΊ/Π²Π΅ΡΠΊΠ°). And other operations do not interest you at the moment.The rewriting of history is a dangerous thing, so it is done in a new unnecessary branch, which can be banged if something goes wrong. And at the end of the procedure, you should have a branch that branches off from the top of your
Π»ΠΎΠΊΠ°Π»ΡΠ½Π°Ρ_Π²Π΅ΡΠΊΠ°and on top of it contains only the changes you need from the fork. You can do merge with--ff-only(see above).
Generally speaking , they do about the same thing. Interactive rebase only eliminates manual digging in the log.
Found the following solution.
I prepared an
importbranch from the common between forks of a commit. and wrote the changes to the server:git branch import 0cc8d855adb457d1860d6e25cb93b6cc75d5a09d git push --allOn the site I created a pull request with a fork in the new branch of interest and accepted it
I downloaded the changes of the new branch, found the commits of interest:
git checkout import git pull origin import git logMerged to the desired commit. There are possible conflicts, but everything went smoothly.
git checkout master git merge a9219aa49e31bd38a6e00b0c0b17428f3fe67229Recorded changes to the server.
git push
Partial pull request in a foreign fork can also be done by creating an additional branch in your fork.
- oneToo hard. Enough was the last three teams. - Pavel Mayorov