The major benefit of rebasing is that you get a linear and much cleaner project history. Yep, when you have uppers done, all the Test branch's commits will be moved onto the head of Master branch. So the best method is we have to use rebase instead of merge (suppose, when in this time, we have solved the branch conflicts).įollowing is one simple sample, for advanced operations, please refer to git checkout master Once we solve the conflicts, or if there is no conflict, we commit and push them git commit -m 'merge test branch'īut this way will lose the changes history logged in test branch, and it would make master branch to be hard for other developers to understand the history of the project. If conflict is encountered, we can run git status to check details about the conflicts and try to solve git status Test merge before commit, avoid a fast-forward commit by -no-ff, So, when we suspect there would some conflicts, we can have following git operations: git checkout test It would "squeeze" all test commits into one merge commit on master that is to say on master branch, we can't see the all change logs of test branch. ![]() It's unsafe, because we don't know if there are any conflicts between test branch and master branch. This is a very practical question, but all the answers above are not practical. The goal in all of this is to keep my test branch updated with the things happening in master and later I could merge them back into master hoping to keep the timeline as linear as possible. Question 2: Which one of these two methods is right? What is the difference there? I am not using -rebase because from my understanding, rebase will get the changes from master and stack mine on top of that hence it could overwrite changes other people made. My work on test is done and I am ready to merge it back to master. Question 1: Is this the right approach? Other developers could have easily worked on same files as I have worked btw. I would do git pull origin master from test. Let's say work on test is taking several days and you want to continuously keep test updated with commits inside master. There are several developers who either commit to master or create other branches and later merge into master. ![]() See Recovering from upstream rebase.A new branch from master is created, we call it test. If someone has pulled your branch, or you have pushed it somewhere, you should merge into it instead, to avoid confusion and extra work on the other end. The actual result after git rebase master in branch feature is this: ( A-B-C ) A'-B'-C' featureĬommits A, B, C are dangling after the rebase, but are reachable through git reflog feature as Merge However, git rebase is only suitable when nobody else is working on it, or there will be confusion and extra work for them, because the old commits A, B, C are now replaced by new commits A', B', C', plus F and G that were not there before. ![]() Taking the example from the git rebase manual, git rebase master in branch feature: A-B-C feature A'-B'-C' featureĭ-E-F-G master D-E-F-G master If the branch has not been distributed to other people, in this case i would prefer git rebase.īecause git rebase makes it as if the changes on the feature branch were made on top of the changes on the master branch, which makes the version graph simpler. You can either git merge master or git rebase master.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |