Merging Branches
Merging is used to integrate changes from one branch into another. This is typically done to incorporate feature branches into the main branch.
Example:
# Merge a branch into the current branch
git merge feature-branch
Rebasing
Rebasing is another way to integrate changes, often used to keep a linear project history.
Example:
# Rebase the current branch onto master
git rebase master
Handling Merge Conflicts
When conflict changes occur, you must resolve them manually.
Example:
# Start a merge
git merge feature-branch
# Resolve conflicts in the affected files
# Mark the conflicts as resolved
git add resolved-file
# Complete the merge
git commit
Comparing and Reviewing Changes
Comparing Changes with Git Diff
The git diff
command shows changes between commits, commit and working tree, etc.
Example:
# Show changes between working directory and staging area
git diff
Reviewing Commits with Git Log
The git log
command displays the commit history.
Example:
# View the commit history
git log
Viewing File Changes with Git Show
The git show
command shows various types of objects, including the file changes in a commit.
Example:
# Show changes in a specific commit
git show commit-hash