search
HomeDevelopment ToolsgitThe difference between git merge and rebase

Connect to Git branch creation and merging. When merging branches, there are two ways: git merge and git rebase.

The difference between git merge and rebase

git merge: Merge and submit two branches into a new submission, and the new submission has 2 parents.

git rebase: will cancel each submission in the branch and store them temporarily, then update the current branch to the latest origin branch, and finally apply all submissions to the branch .

git merge

Specific operations: bob modified 2 times in index1.html and submitted it to the remote warehouse; lilei modified 2 times in index.html times and submit it to the remote warehouse; bob pulls the remote warehouse (git fetch origin dev) and merges it. The branch structure is as follows:

The difference between git merge and rebase

It can be seen that the two branches are merged, and the 93a6d33 commit has 2 parents (135b375 and 8b61b04).

git rebase

Specific operations: lilei modified 2 times in index.html and submitted it to the remote warehouse; bob modified 2 times in index1.html and submitted it to the remote warehouse. Submit, pull the remote warehouse (git fetch origin dev), rebase and merge. The command line output is as follows:

The difference between git merge and rebase

First move the HEAD pointer to the top of the current origin branch, and then apply all commits to the current branch. The branch structure (in a straight line) is as follows:

The difference between git merge and rebase

It can be seen that during rebase, the current branch will commit 191b8cd, 00e08ec and the following two submissions based on the common ancestor of 135b375 , a total of 4 submissions were withdrawn. Then move HEAD to commit 322ca9 and reapply the 4 commits to the branch.

The above is the detailed content of The difference between git merge and rebase. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to create a git projectHow to create a git projectApr 17, 2025 pm 02:45 PM

Answer: The steps involved in creating a Git project include: Install Git. Initialize the Git repository. Add files to the temporary storage area. Submit changes and add a description. (Optional) Create a remote repository. (Optional) Push (upload) changes to the remote repository.

How to add public keys to git accountHow to add public keys to git accountApr 17, 2025 pm 02:42 PM

How to add a public key to a Git account? Step: Generate an SSH key pair. Copy the public key. Add a public key in GitLab or GitHub. Test the SSH connection.

How to add environment variables to gitHow to add environment variables to gitApr 17, 2025 pm 02:39 PM

为 Git 添加环境变量的方法:修改 .gitconfig 文件。 Add env = KEY=VALUE in the [core] block. Save and exit the file.重新加载 Git 配置(git config --reload)。验证环境变量(git config --get core.env.MY_ENV_VAR)。

How to separate git commitHow to separate git commitApr 17, 2025 pm 02:36 PM

Use git to submit code separately, providing granular change tracking and independent work ability. The steps are as follows: 1. Add the changed files; 2. Submit specific changes; 3. Repeat the above steps; 4. Push submission to the remote repository.

How to detect ssh by gitHow to detect ssh by gitApr 17, 2025 pm 02:33 PM

To detect SSH through Git, you need to perform the following steps: Generate an SSH key pair. Add the public key to the Git server. Configure Git to use SSH. Test the SSH connection. Solve possible problems according to actual conditions.

How to query uploaded code in gitHow to query uploaded code in gitApr 17, 2025 pm 02:30 PM

To query the code uploaded to the Git repository, use the following command: View the commit record list: git log By commit hash query: git log <Commit hash>Search by commit information: git log -S <Search string>Query by file path: git log -S <Search string> -- <File path>Compare changes between two commits: git diff <Start commit hash> <End commit hash>View special

How to connect to the public network of git serverHow to connect to the public network of git serverApr 17, 2025 pm 02:27 PM

Connecting a Git server to the public network includes five steps: 1. Set up the public IP address; 2. Open the firewall port (22, 9418, 80/443); 3. Configure SSH access (generate key pairs, create users); 4. Configure HTTP/HTTPS access (install servers, configure permissions); 5. Test the connection (using SSH client or Git commands).

What to do if git submits a staggered branchWhat to do if git submits a staggered branchApr 17, 2025 pm 02:24 PM

After committing to the wrong branch, you can resolve it by: Determine that the wrong branch creates a new branch, pointing to the correct branch apply the commit to the new branch Push the new branch to the remote repository to delete the wrong branch. Force update the remote branch

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools