# Create the git repository
mkdir test2
cd test2
git init
# Add some files
echo "Content" > file1.txt
echo "Content" > file2.txt
git add .
git commit -m "Initial commit"
# Check commits
git log --oneline
The result:
c14c3f6 (HEAD -> master) Initial commit
echo "Added a new line" >> file1.txt
git add .
git commit -m "Second commit in master"
git log --oneline
The result:
1c4db7a (HEAD -> master) Second commit in master
c14c3f6 Initial commit
git checkout -b branch1
echo "More lines in fileee1" >> file1.txt
git add .
git commit -m "Add more lines on file1"
sed -i -e "s/fileee1/file1/g" file1.txt
git add file1.txt
git commit -m "Fix typo"
echo "*.txt-e" >> .gitignore
git add .
git commit -m "Added .gitignore"
git log --oneline
The result:
14bdb2d (HEAD -> branch1) Added .gitignore
db26032 Fix typo
e7596e0 Add more lines on file1
1c4db7a (master) Second commit in master
c14c3f6 Initial commit
git reset --soft master # This is the equivalent of "git rebase --interative master" where I select FIX-UP
git add .
git commit -m "Rebase FIX-UP"
git log --oneline
The result:
e697511 (HEAD -> branch1) Rebase FIX-UP
1c4db7a (master) Second commit in master
c14c3f6 Initial commit
git checkout master
git merge --no-edit branch1
git branch -D branch1
git log --oneline
The result:
06f98ca (HEAD -> master) Merge branch 'branch1'
e697511 Rebase FIX-UP
1c4db7a Second commit in master
c14c3f6 Initial commit
git checkout -b branch2
echo "Add one line" >> file1.txt
git add .
git commit -m "Add one line to file1"
echo "Add other line line" >> file1.txt
git add .
git commit -m "Add other line to file1"
git log --oneline
The result:
0c83bd3 (HEAD -> branch2) Add other line to file1
321cb1e Add one line to file1
06f98ca (master) Merge branch 'branch1'
e697511 Rebase FIX-UP
1c4db7a Second commit in master
c14c3f6 Initial commit
Now, rebase working branch into a single commit
git reset --soft master # This is the equivalent of "git rebase --interative master" where I select FIX-UP
git add .
git commit -m "Rebase branch2 FIX-UP"
git log --oneline
The result:
14665f1 (HEAD -> branch2) Rebase branch2 FIX-UP
06f98ca (master) Merge branch 'branch1'
e697511 Rebase FIX-UP
1c4db7a Second commit in master
c14c3f6 Initial commit
Merge the rebased branch.
git checkout master
git merge --no-edit branch2
git branch -D branch2
git log --oneline
The result:
14665f1 (HEAD -> master) Rebase branch2 FIX-UP
06f98ca Merge branch 'branch1'
e697511 Rebase FIX-UP
1c4db7a Second commit in master
c14c3f6 Initial commit
git log -p file1.txt | grep commit