Fusionner plusieurs commits d’une feature branche vers master

Quand on travaille sur une branche de développement en parallèle et qu’on souhaite déporter son travail sur la branche master on a deux manières de le faire. La première, -plus simple-, consiste à faire un merge à partir de master alors que la seconde, -plus difficile-, consiste à faire un rebase (en renommant, fusionnant les commits au passage).

Méthode 1 : Facile

On se place sur la branche master et on met à jour les données

[shell]
git checkout master
git fetch
git pull
[/shell]

On merge la branche dérivée depuis master

[shell]git merge feature_branch[/shell]

On annule toutes les modifications faites sur la branche dérivée (de manière soft/mixed)

[shell]git reset origin/master[/shell]

Toutes les modifications annulées se mettent ‘fichiers modifiés’
A partir de la on peut créer un nouveau commit et pusher le tout
On a donc toutes les modifications faites dans la branche dérivée en un seul commit dans master.

[shell]
git add –all
git commit
[/shell]

Méthode 2 : Difficile

Le squash commit n’est pas toujours simple, c’est pour ça qu’on va commencer par dériver une branche spécialement pour cette manipulation (on ne sait jamais!…). Pour squasher tous les commits depuis le dernier commit en commun avec master :

[shell]
git checkout -b squashed_feature
git rebase -i master
[/shell]

L’éditeur s’ouvre avec les liste des commits

[shell]
pick fda59df commit 1
pick x536897 commit 2
pick c01a668 commit 3
[/shell]

Les commits sont classés par ordre d’ancienneté (le plus ancien se trouve tout en bas de la liste). On va donc garder commit 1 (qui représente la dernière version du code), dans lequel on va squasher les autres, on ajoute donc le mot-clé “squash” devant chacun d’eux :

[shell]
pick fda59df commit 1
squash x536897 commit 2
squash c01a668 commit 3
[/shell]

Si on supprime une ligne, le commit sera ignoré, et perdu. Après avoir enregistré, l’éditeur s’ouvre à nouveau et demande un message pour le nouveau squash commit.

Voilà, il ne reste plus qu’à merger l’unique commit de la branche squashed_feature vers master.

[shell]
git checkout master
git merge squashed_feature
[/shell]

39 Comments Fusionner plusieurs commits d’une feature branche vers master

  1. Richard

    Unquestionably believe that which you stated. Your favorite reason appeared to
    be on the net the easiest thing to be aware of.
    I say to you, I definitely get annoyed while
    people think about worries that they plainly don’t know about.
    You managed to hit the nail upon the top and
    defined out the whole thing without having side-effects , people could take a
    signal. Will probably be back to get more. Thanks

    Reply
  2. Jeremy

    I think the admin of this website is actually working hard in support of his site, since here every information is
    quality based data.

    Feel free to surf to my homepage – ntc33 (Jeremy)

    Reply
  3. 918kaya android

    Hi there, just became aware of your blog through Google, and
    found that it’s really informative. I am going to watch out for brussels.
    I will appreciate if you continue this in future.
    Numerous people will be benefited from your writing.

    Cheers!

    Look at my homepage; 918kaya android

    Reply
  4. Mag-wiki.Win

    What i d᧐ not understοod is if trutһ be told how you’re no longer actually much more well-preferreԁ than yyou may be now.
    You are ѕo intelligent. You aⅼready kow thus considerably with гegards to this sսbject, made
    me in my view believe it ftom numerous numerous angles.
    Ιts like women and men are not fascinated unless it
    is one thing to acckmplish with Lady gaga!
    Үour personal stuffs great. Always care for it up!

    Reply
  5. Rosaline

    Hmm is anyone else experiencing problems with the pictures on this blog loading?

    I’m trying to figure out if its a problem on my end or if it’s the blog.
    Any feed-back would be greatly appreciated.

    Reply
  6. https://joker123slots.com

    Saya telah menjelajah online lebih dari 2 jam hari ini, namun saya tidak pernah menemukan artikel menarik seperti milik
    Anda. It’s cukup berharga bagi saya. Dalam pandangan saya, jika
    semua pemilik situs web dan blogger membuat konten yang baik seperti yang Anda lakukan, internet akan menjadi lebih berguna dari sebelumnya.

    my web site: 123 joker slot (https://joker123slots.com)

    Reply
  7. slots

    Spot on with this write-up, I really feel this web site needs a great deal more attention. I’ll probably
    be returning to read through more, thanks for the advice!

    Reply
  8. infonya disini

    Нey Ι know this is off tοpiϲ but I was w᧐ndering if you knew of аnny widgets I coսⅼd add to mʏ blog thɑt automatically
    tweеt myy newest twitrer updatеs. I’ve Ƅeen looking for a plug-in like this for quite some time aand was hoping maybe you would һave
    some experience wіth something ⅼike this. Please let
    me know if you run into anything. I truly enjoy гeading your blog and I looк forward to
    your new updates.

    Reply
  9. club suncity test id

    Hey I know this is off topic but I was wondering if you knew of any widgets I
    could add to my blog that automatically tweet my newest
    twitter updates. I’ve been looking for a plug-in like
    this for quite some time and was hoping maybe you would have some experience with something like this.

    Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward
    to your new updates.

    My web site – club suncity test id

    Reply
  10. Aracely

    Saya akan segera kopling rss feed Anda karena saya tidak
    bisa
    Ini waktu terbaik untuk membuat beberapa rencana untuk masa depan dan sekarang waktu untuk berbahagia.
    Saya telah membaca posting ini dan jika saya bisa, saya ingin menyarankan Anda beberapa hal menarik atau saran .
    Mungkin Anda bisa menulis artikel berikutnya
    yang mengacu pada artikel ini. Saya ingin membaca lebih hal tentang itu!

    Have a look at my web blog Live chat joker338 (Aracely)

    Reply
  11. xe88sg.com

    We stumbled over here different website and thought I may
    as well check things out. I like what I see so now
    i’m following you. Look forward to exploring your web page yet
    again.

    Look into my page – hengheng2 rollex11 [xe88sg.com]

    Reply
  12. Porter

    I’m gone to tell my little brother, that he should also
    visit this web site on regular basis to obtain updated from latest information.

    Review my homepage … wm casino pc – Porter,

    Reply
  13. Lashay

    great put up, very informative. I’m wondering
    why the other specialists of this sector don’t understand this.
    You should continue your writing. I am sure, you’ve a great readers’ base already!

    Look into my web site – game mega888 (Lashay)

    Reply
  14. calibet original

    Its like you learn my thoughts! You appear to grasp so much approximately this,
    such as you wrote the book in it or something. I feel that you just can do with a few % to drive the message home a bit,
    however other than that, that is magnificent blog. An excellent read.
    I will definitely be back.

    Also visit my webpage calibet original

    Reply
  15. kunjungi situs

    Havе you ever ϲonsidered abbout adding a ⅼittle bit
    more than juѕt your articles? I mean, what you say is important annd eѵerything.
    Nevertheless think of if you added some great images ߋr videos to give yolur posts more, “pop”!
    Your content is excellent but witһ pics and clips, this site could certainly
    be one of tthe greatest in its niche. Very ɡood blog!

    Reply

Leave a Reply

Your email address will not be published.