Skip to main content
added 597 characters in body
Source Link
rashok
  • 13.2k
  • 17
  • 90
  • 101

Procedure 3

  1. If need to add new changes to the last commit means --amend can be used with git-commit.
    # git log --pretty=oneline --abbrev-commit
    cdababcd Fix issue B
    deab3412 Fix issue A
    ....
    # git add <files> # New changes
    # git commit --amend
    # git log --pretty=oneline --abbrev-commit
    1d4ab2e1 Fix issue B
    deab3412 Fix issue A
    ....  

Here --amend merges the new changes to last commit cdababcd and generates new commit ID 1d4ab2e1

Conclusion

  • Advantage of 1st procedure is to squash multiple commits and to reorder. But this procedure will be difficult if we need to merge a fix to very old commit.
  • So the 2nd procedure helps to merge the commit to very old commit easily.
  • And the 3rd procedure is useful in a case to squash a new changes to last commit.

Conclusion

  • Advantage of 1st procedure is to squash multiple commits and to reorder. But this procedure will be difficult if we need to merge a fix to very old commit.
  • So the 2nd procedure helps to merge the commit to very old commit easily.

Procedure 3

  1. If need to add new changes to the last commit means --amend can be used with git-commit.
    # git log --pretty=oneline --abbrev-commit
    cdababcd Fix issue B
    deab3412 Fix issue A
    ....
    # git add <files> # New changes
    # git commit --amend
    # git log --pretty=oneline --abbrev-commit
    1d4ab2e1 Fix issue B
    deab3412 Fix issue A
    ....  

Here --amend merges the new changes to last commit cdababcd and generates new commit ID 1d4ab2e1

Conclusion

  • Advantage of 1st procedure is to squash multiple commits and to reorder. But this procedure will be difficult if we need to merge a fix to very old commit.
  • So the 2nd procedure helps to merge the commit to very old commit easily.
  • And the 3rd procedure is useful in a case to squash a new changes to last commit.
added 2 characters in body
Source Link
rashok
  • 13.2k
  • 17
  • 90
  • 101

Procedure 1

  1. Identify the commit short hash

    git log --pretty=oneline --abbrev-commit

    abcd1234 Update to Fix for issue B cdababcd Fix issue B deab3412 Fix issue A .... Here even git log --oneline also can be used to get short hash.

  2. If you want to squash (merge) last two commit

    git rebase -i deab3412

  3. This opens up a nano editor for merging. And it looks like below

    .... pick cdababcd Fix issue B pick abcd1234 Update to Fix for issue B ....

  4. Rename the word pick to squash which is present before abcd1234. After rename it should be like below.

    .... pick cdababcd Fix issue B squash abcd1234 Update to Fix for issue B ....

  5. Now save and close the nano editor. Press ctrl + o and press Enter to save. And then press ctrl + x to exit the editor.

  6. Then nano editor again opens for updating comments, if necessary update it.

  7. Now its squashed successfully, you can verify it by checking logs.

    git log --pretty=oneline --abbrev-commit

    1122abcd Fix issue B deab3412 Fix issue A ....

  8. Now push to repo. Note to add + sign before the branch name. This means forced push.

    git push origin +master

Note : This is based on using git on ubuntu shell. If you are using different os (Windows or Mac) then above commands are same except editor. You might get different editor.

Procedure 2

  1. First add the required files for commit
git add <files>
  1. Then commit using --fixup option and the OLDCOMMIT should be on which we need to merge(squash) this commit.
git commit --fixup=OLDCOMMIT

Now this creates a new commit on top of HEAD with fixup1 <OLDCOMMIT_MSG>. 3. After need to execute below command to merge(squash) the new commit to the OLDCOMMIT.

  1. Then execute below command to merge(squash) the new commit to the OLDCOMMIT.
git rebase --interactive --autosquash OLDCOMMIT^

Here ^ means the previous commit to OLDCOMMIT. This rebase command opens interactive window on a editor (vim or nano) on that we no need to do anything just save and exiting is sufficient. Because the option passed to this will automatically move the latest commit to next to old commit and change the operation to fixup (equivalent to squash). Then rebase continues and finishes.

Conclusion

  • Advantage of 1st procedure is to squash multiple commits and to reorder. But this procedure will be difficult if we need to merge a fix to very old commit.
  • So the 2nd procedure helps to merge the commit to very old commit easily.

Procedure 1

  1. Identify the commit short hash

    git log --pretty=oneline --abbrev-commit

    abcd1234 Update to Fix for issue B cdababcd Fix issue B deab3412 Fix issue A .... Here even git log --oneline also can be used to get short hash.

  2. If you want to squash (merge) last two commit

    git rebase -i deab3412

  3. This opens up a nano editor for merging. And it looks like below

    .... pick cdababcd Fix issue B pick abcd1234 Update to Fix for issue B ....

  4. Rename the word pick to squash which is present before abcd1234. After rename it should be like below.

    .... pick cdababcd Fix issue B squash abcd1234 Update to Fix for issue B ....

  5. Now save and close the nano editor. Press ctrl + o and press Enter to save. And then press ctrl + x to exit the editor.

  6. Then nano editor again opens for updating comments, if necessary update it.

  7. Now its squashed successfully, you can verify it by checking logs.

    git log --pretty=oneline --abbrev-commit

    1122abcd Fix issue B deab3412 Fix issue A ....

  8. Now push to repo. Note to add + sign before the branch name. This means forced push.

    git push origin +master

Note : This is based on using git on ubuntu shell. If you are using different os (Windows or Mac) then above commands are same except editor. You might get different editor.

Procedure 2

  1. First add the required files for commit
git add <files>
  1. Then commit using --fixup option and the OLDCOMMIT should be on which we need to merge(squash) this commit.
git commit --fixup=OLDCOMMIT

Now this creates a new commit on top of HEAD with fixup1 <OLDCOMMIT_MSG>. 3. After need to execute below command to merge(squash) the new commit to the OLDCOMMIT.

git rebase --interactive --autosquash OLDCOMMIT^

Here ^ means the previous commit to OLDCOMMIT. This rebase command opens interactive window on a editor (vim or nano) on that we no need to do anything just save and exiting is sufficient. Because the option passed to this will automatically move the latest commit to next to old commit and change the operation to fixup (equivalent to squash). Then rebase continues and finishes.

Conclusion

  • Advantage of 1st procedure is to squash multiple commits and to reorder. But this procedure will be difficult if we need to merge a fix to very old commit.
  • So the 2nd procedure helps to merge the commit to very old commit easily.

Procedure 1

  1. Identify the commit short hash

    git log --pretty=oneline --abbrev-commit

    abcd1234 Update to Fix for issue B cdababcd Fix issue B deab3412 Fix issue A .... Here even git log --oneline also can be used to get short hash.

  2. If you want to squash (merge) last two commit

    git rebase -i deab3412

  3. This opens up a nano editor for merging. And it looks like below

    .... pick cdababcd Fix issue B pick abcd1234 Update to Fix for issue B ....

  4. Rename the word pick to squash which is present before abcd1234. After rename it should be like below.

    .... pick cdababcd Fix issue B squash abcd1234 Update to Fix for issue B ....

  5. Now save and close the nano editor. Press ctrl + o and press Enter to save. And then press ctrl + x to exit the editor.

  6. Then nano editor again opens for updating comments, if necessary update it.

  7. Now its squashed successfully, you can verify it by checking logs.

    git log --pretty=oneline --abbrev-commit

    1122abcd Fix issue B deab3412 Fix issue A ....

  8. Now push to repo. Note to add + sign before the branch name. This means forced push.

    git push origin +master

Note : This is based on using git on ubuntu shell. If you are using different os (Windows or Mac) then above commands are same except editor. You might get different editor.

Procedure 2

  1. First add the required files for commit
git add <files>
  1. Then commit using --fixup option and the OLDCOMMIT should be on which we need to merge(squash) this commit.
git commit --fixup=OLDCOMMIT

Now this creates a new commit on top of HEAD with fixup1 <OLDCOMMIT_MSG>.

  1. Then execute below command to merge(squash) the new commit to the OLDCOMMIT.
git rebase --interactive --autosquash OLDCOMMIT^

Here ^ means the previous commit to OLDCOMMIT. This rebase command opens interactive window on a editor (vim or nano) on that we no need to do anything just save and exiting is sufficient. Because the option passed to this will automatically move the latest commit to next to old commit and change the operation to fixup (equivalent to squash). Then rebase continues and finishes.

Conclusion

  • Advantage of 1st procedure is to squash multiple commits and to reorder. But this procedure will be difficult if we need to merge a fix to very old commit.
  • So the 2nd procedure helps to merge the commit to very old commit easily.
added 1135 characters in body
Source Link
rashok
  • 13.2k
  • 17
  • 90
  • 101

Procedure 1

  1. Identify the commit short hash

    git log --pretty=oneline --abbrev-commit

    abcd1234 Update to Fix for issue B cdababcd Fix issue B deab3412 Fix issue A .... Here even git log --oneline also can be used to get short hash.

  2. If you want to squash (merge) last two commit

    git rebase -i deab3412

  3. This opens up a nano editor for merging. And it looks like below

    .... pick cdababcd Fix issue B pick abcd1234 Update to Fix for issue B ....

  4. Rename the word pick to squash which is present before abcd1234. After rename it should be like below.

    .... pick cdababcd Fix issue B squash abcd1234 Update to Fix for issue B ....

  5. Now save and close the nano editor. Press ctrl + o and press Enter to save. And then press ctrl + x to exit the editor.

  6. Then nano editor again opens for updating comments, if necessary update it.

  7. Now its squashed successfully, you can verify it by checking logs.

    git log --pretty=oneline --abbrev-commit

    1122abcd Fix issue B deab3412 Fix issue A ....

  8. Now push to repo. Note to add + sign before the branch name. This means forced push.

    git push origin +master

Note : This is based on using git on ubuntu shell. If you are using different os (Windows or Mac) then above commands are same except editor. You might get different editor.

Procedure 2

  1. First add the required files for commit
git add <files>
  1. Then commit using --fixup option and the OLDCOMMIT should be on which we need to merge(squash) this commit.
git commit --fixup=OLDCOMMIT

Now this creates a new commit on top of HEAD with fixup1 <OLDCOMMIT_MSG>. 3. After need to execute below command to merge(squash) the new commit to the OLDCOMMIT.

git rebase --interactive --autosquash OLDCOMMIT^

Here ^ means the previous commit to OLDCOMMIT. This rebase command opens interactive window on a editor (vim or nano) on that we no need to do anything just save and exiting is sufficient. Because the option passed to this will automatically move the latest commit to next to old commit and change the operation to fixup (equivalent to squash). Then rebase continues and finishes.

Conclusion

  • Advantage of 1st procedure is to squash multiple commits and to reorder. But this procedure will be difficult if we need to merge a fix to very old commit.
  • So the 2nd procedure helps to merge the commit to very old commit easily.
  1. Identify the commit short hash

    git log --pretty=oneline --abbrev-commit

    abcd1234 Update to Fix for issue B cdababcd Fix issue B deab3412 Fix issue A .... Here even git log --oneline also can be used to get short hash.

  2. If you want to squash (merge) last two commit

    git rebase -i deab3412

  3. This opens up a nano editor for merging. And it looks like below

    .... pick cdababcd Fix issue B pick abcd1234 Update to Fix for issue B ....

  4. Rename the word pick to squash which is present before abcd1234. After rename it should be like below.

    .... pick cdababcd Fix issue B squash abcd1234 Update to Fix for issue B ....

  5. Now save and close the nano editor. Press ctrl + o and press Enter to save. And then press ctrl + x to exit the editor.

  6. Then nano editor again opens for updating comments, if necessary update it.

  7. Now its squashed successfully, you can verify it by checking logs.

    git log --pretty=oneline --abbrev-commit

    1122abcd Fix issue B deab3412 Fix issue A ....

  8. Now push to repo. Note to add + sign before the branch name. This means forced push.

    git push origin +master

Note : This is based on using git on ubuntu shell. If you are using different os (Windows or Mac) then above commands are same except editor. You might get different editor.

Procedure 1

  1. Identify the commit short hash

    git log --pretty=oneline --abbrev-commit

    abcd1234 Update to Fix for issue B cdababcd Fix issue B deab3412 Fix issue A .... Here even git log --oneline also can be used to get short hash.

  2. If you want to squash (merge) last two commit

    git rebase -i deab3412

  3. This opens up a nano editor for merging. And it looks like below

    .... pick cdababcd Fix issue B pick abcd1234 Update to Fix for issue B ....

  4. Rename the word pick to squash which is present before abcd1234. After rename it should be like below.

    .... pick cdababcd Fix issue B squash abcd1234 Update to Fix for issue B ....

  5. Now save and close the nano editor. Press ctrl + o and press Enter to save. And then press ctrl + x to exit the editor.

  6. Then nano editor again opens for updating comments, if necessary update it.

  7. Now its squashed successfully, you can verify it by checking logs.

    git log --pretty=oneline --abbrev-commit

    1122abcd Fix issue B deab3412 Fix issue A ....

  8. Now push to repo. Note to add + sign before the branch name. This means forced push.

    git push origin +master

Note : This is based on using git on ubuntu shell. If you are using different os (Windows or Mac) then above commands are same except editor. You might get different editor.

Procedure 2

  1. First add the required files for commit
git add <files>
  1. Then commit using --fixup option and the OLDCOMMIT should be on which we need to merge(squash) this commit.
git commit --fixup=OLDCOMMIT

Now this creates a new commit on top of HEAD with fixup1 <OLDCOMMIT_MSG>. 3. After need to execute below command to merge(squash) the new commit to the OLDCOMMIT.

git rebase --interactive --autosquash OLDCOMMIT^

Here ^ means the previous commit to OLDCOMMIT. This rebase command opens interactive window on a editor (vim or nano) on that we no need to do anything just save and exiting is sufficient. Because the option passed to this will automatically move the latest commit to next to old commit and change the operation to fixup (equivalent to squash). Then rebase continues and finishes.

Conclusion

  • Advantage of 1st procedure is to squash multiple commits and to reorder. But this procedure will be difficult if we need to merge a fix to very old commit.
  • So the 2nd procedure helps to merge the commit to very old commit easily.
added 91 characters in body
Source Link
rashok
  • 13.2k
  • 17
  • 90
  • 101
Loading
added 84 characters in body
Source Link
rashok
  • 13.2k
  • 17
  • 90
  • 101
Loading
added 1 character in body
Source Link
rashok
  • 13.2k
  • 17
  • 90
  • 101
Loading
added 969 characters in body
Source Link
rashok
  • 13.2k
  • 17
  • 90
  • 101
Loading
Source Link
rashok
  • 13.2k
  • 17
  • 90
  • 101
Loading