11/9/2022 0 Comments Sublime merge interactive rebaseThe most common usage scenarios of the two are therefore different: In interactive mode, it allows us to rewrite, reorder, and delete commits through the editor and specific command rules before reapplying. In the standard mode of rebase, the commits of the current working branch are applied directly to the tip of the incoming branch. Add the -i or -interactive option after the command to use the interactive mode.Īs we mentioned earlier, rebase is “reapplying commits on top of another base”, and in the process of reapplying, these commits are recreated and can naturally be modified. In the previous examples, we used the default standard mode. The git rebase command has two modes: standard and interactive. Rewrite commit history using rebase’s interactive mode. Note that as with rebase, Git doesn’t actually modify and replace the previous commit internally, but instead creates a brand new commit and repoints this new commit. On the premise of ensuring that the branch is not a public branch, we can use git push -force Force push. If we have already pushed the last commit to the remote branch and executing the push now will prompt an error and be rejected. These changes will be applied to the last commit. After execution, a new editor window will be entered, and the submission information of the last submission can be modified. Or we just feel that the commit message from the last commit was not written well enough and want to make some changes.Īt this time, we can add new modifications (or skip), and use the git commit -amend command to execute the submission.We can quickly complete the revision, but we don’t want to add a separate commit. Suddenly I found that the last commit still left some small tails unfinished, such as a line of comments that we forgot to delete or a small clerical error.We just made a commitment, but haven’t pushed to the public branch yet.Using git commit -amend is more convenient when we only want to amend the most recent commit. The execution process is shown in the following figure: Switch back to the master branch and perform a fast-forward merge: git checkout master & git merge fature.To merge updates from the master branch: git merge master.Switch to the feature branch: git checkout feature.Now we will use the merge and rebase respectively to integrate the B and C commits of the master branch into the feature branch, add a commit F to the feature branch, then merge the feature branch into the master, and finally compare the commits formed by the two methods differ in history. Suppose we have the following branches: D-E feature / A-B-C master The above scenarios can also be achieved using merge, but using rebase allows us to maintain a linear and cleaner commit history. We want to integrate the latest changes from master in the feature branch.The remote master branch later merged some new commits.We pulled a feature branch from the master branch for feature development locally.The following usage scenarios are common in most Git workflows: Rebase is often used to rewrite commit history. The essence of the rebase operation is to discard some existing commits, and then correspondingly create some new commits that are identical in content but are actually different. We can also understand the above as changing the base of the Feature branch from commit A to commit C, which looks like the branch was created from commit C, and commits D and E.īut actually, this is just “looking”, internally Git copies the contents of commits D and E, creates new commits D’ and E’ and applies them to a specific base (A→B→C).Īlthough the new Feature branch looks the same as before, it is made up of brand new commits. Then compare the previous commits (D and E) of the current branch relative to the ancestor commit, extract the corresponding modifications and save them as temporary files, and then point the current branch to the commit Cpointed to by the target base Master.įinally, using this as the new base end, the modifications previously saved as temporary files are applied sequentially. The execution process of rebase is to first find the nearest common ancestor commit A of these two branches (that is, the current branch Feature, the target base branch Master of the rebase operation). In order to keep the commit history clean, we can switch to the Feature branch to perform the rebase operation: git rebase master Now for some reason, for example, the development of new features depends on commits B and C, and we need to integrate the two new commits of Master into the Feature branch. Then Master added two new commits B and C, and Feature added two new commits D and E. Suppose we create a Feature branch from Master’s commit A for new feature development, then A is the base end of Feature.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |