Good day. There is a master and temp branch, how to add a temp branch to the master without changes in commit 3 commit and therd commit (no matter how, yes, I can’t write third).

enter image description here

  • git merge / git rebase / git cherry-pick - choose - KoVadim
  • And which one will you advise?) - koshachok
  • Need to migrate only two commits? - KoVadim
  • I want to understand the principle itself, i.e. let temp be a working branch in which there are crutches commits (which help the local version to work), but there is a master to which I want to transfer changes without these crutches. Well, respectively, the master quietly works without crutches, since it works non - locally - koshachok

2 answers 2

You need to roll back the changes made in these commits. Օ roll those commits that are not needed like this:

 git revert commit-hash 

commit-hash is a hash of the commit code, and then you can do a merge .

A commit hash can be viewed with this program .

  • But if, I still need these commits, but I want to transfer the code without them to the master - koshachok
  • @koshachok I don’t remember another way now, but if you still need it, make a new branch out of the current branch, and then remove the commit from the current one as I said. - Raz Galstyan

Judging by the wording of the question - you just need to transfer only two committees. This is a job for cherry-pick.

The easiest way:

  • first go to the temp branch, make git log and remember the hashes of the necessary commits (you can write the first 5-6 characters on a leaflet, you don’t need to remember all).
  • go to the master branch and do twice a cherry-pick , sequentially pointing out the hashes written above:

     git cherry-pick <хеш> 

    order hashes do what you need. It may well happen that in the process of applying a commit a conflict may occur - it needs to be resolved and handled. By default, cherry-pick commits as an automaton. If you don't want this (well, there is little), you can simply add the -n parameter.

     git cherry-pick -n <хеш> 
  • PROFIT!

Of course, you can do it through rebase, but I think I will talk longer, and the result will be the same.