From 944ebd48790a03000ebaf84513e171bedeec2fef Mon Sep 17 00:00:00 2001 From: Chandan-Chainani Date: Thu, 3 Oct 2024 15:17:48 +0530 Subject: [PATCH 1/2] [Rebase-Exec] exercise more intuitive #242 --- rebase-exec/README.md | 33 ++++++++++++++++++++------------- rebase-exec/setup.ps1 | 33 +-------------------------------- rebase-exec/setup.sh | 22 +--------------------- rebase-exec/verify.ps1 | 10 ---------- rebase-exec/verify.sh | 8 -------- 5 files changed, 22 insertions(+), 84 deletions(-) delete mode 100644 rebase-exec/verify.ps1 delete mode 100644 rebase-exec/verify.sh diff --git a/rebase-exec/README.md b/rebase-exec/README.md index a3c471f3..a262dcb6 100644 --- a/rebase-exec/README.md +++ b/rebase-exec/README.md @@ -6,16 +6,23 @@ ## Task -Doing local development we've created a bunch of commits. We would like to deliver them all to master. We would also like all commits to pass our tests. - -Our test suite is contained in `test.sh`. We can use `git rebase --exec` to run the test suite for all commits. We have tagged the first commit in our history with `initial-commit`. - -1. Run the test script using `./test.sh` to see the most recent commit succeed -1. Use `git rebase -i --exec ./test.sh initial-commit` to run the test script on all commits. You will be shown the plan, you do not need to change anything. -1. The tests will run, and fail on a single commit. The tests fail because the test script changes. So you need to fix it -1. Change the following strings in `test.sh` - - `One test failed` to `all tests pass` - - `exit 1` to `exit 0` -1. Stage `test.sh` and use `git commit --amend` to fix the broken commit -1. Run `git rebase --continue` to execute the test suite on the remaining commits -1. You may run `verify.sh` (or `verify.ps1` in PowerShell) to verify your solution +### Example 1: +Adding content to file in last 3 commits using `git rebase -i --exec HEAD~3`. + +1. Run `git log --patch` command to see what changes are include in last commit. +2. Run `git rebase -i --exec "echo '1' >> 4.txt && git add 4.txt && git commit --amend --no-edit" HEAD~3` command it will open configured editor with information what command will be executed for each commits which is notified by `exec ` you can either modify the command or save and exit the editor to let the command run for that specific commit. +3. Run `git log --patch` command to see what are the changes in commits. + +### Example 2: +Change the author for all the commits using `git rebase -i --exec`. + +1. Run `git log --format="commit: %H%nauthor: %an%n"` command to see detail related to commit and author. +2. Run `git rebase -i --root --exec "git commit --amend --author='my name ' --no-edit"` command it will open configured editor with information what command will be executed for each commits which is notified by `exec ` you can either modify the command or save and exit the editor to let the command run for that specific commit. +3. Run `git log --format="commit: %H%nauthor: %an%n"` command to see the changes author information for the commits. + +## Useful commands + +- `git log --patch` +- `git rebase -i --exec "echo '1' >> 4.txt && git add 4.txt && git commit --amend --no-edit" HEAD~3` +- `git log --format="commit: %H%nauthor: %an%n"` +- `git rebase -i --root --exec "git commit --amend --author='my name ' --no-edit"` or `git rebase -i --exec "git commit --amend --author='my name ' --no-edit" first-commit` \ No newline at end of file diff --git a/rebase-exec/setup.ps1 b/rebase-exec/setup.ps1 index 4233a8b6..05e84e3b 100644 --- a/rebase-exec/setup.ps1 +++ b/rebase-exec/setup.ps1 @@ -1,20 +1,9 @@ . ..\utils\make-exercise-repo.ps1 -$testScript = @' -#! /usr/bin/env bash -echo "Running tests on commit $(git rev-parse --short HEAD)" -echo 'all tests pass' -exit 0 -'@ -Set-Content "test.sh" $testScript - -git add 'test.sh' -git commit -m "Initial commit" -git tag initial-commit - Set-Content "1.txt" -Value "" git add 1.txt git commit -m "1" +git tag first-commit Set-Content "2.txt" -Value "" git add 2.txt @@ -22,16 +11,6 @@ git commit -m "2" Set-Content "3.txt" -Value "" git add 3.txt - -$testScript = @' -#! /usr/bin/env bash -echo "Running tests on commit $(git rev-parse --short HEAD)" -echo 'One failing test' -exit 1 -'@ -Set-Content "test.sh" $testScript - -git add 'test.sh' git commit -m "3" Set-Content "4.txt" -Value "" @@ -40,18 +19,8 @@ git commit -m "4" Set-Content "5.txt" -Value "" git add 5.txt -$testScript = @' -#! /usr/bin/env bash -echo "Running tests on commit $(git rev-parse --short HEAD)" -echo 'all tests pass' -exit 0 -'@ -Set-Content "test.sh" $testScript -git add 'test.sh' git commit -m "5" Set-Content "6.txt" -Value "" git add 6.txt git commit -m "6" - - diff --git a/rebase-exec/setup.sh b/rebase-exec/setup.sh index fcdd3425..4d6d1f41 100755 --- a/rebase-exec/setup.sh +++ b/rebase-exec/setup.sh @@ -4,18 +4,10 @@ source ../utils/utils.sh make-exercise-repo -echo "#! /usr/bin/env bash" > 'test.sh' -echo 'echo "Running tests on commit $(git rev-parse --short HEAD)"' >> 'test.sh' -echo "echo 'all tests pass'" >> 'test.sh' -echo "exit 0" >> 'test.sh' -chmod +x 'test.sh' -git add 'test.sh' -git commit -m "Initial commit" -git tag initial-commit - touch 1.txt git add 1.txt git commit -m "1" +git tag first-commit touch 2.txt git add 2.txt @@ -23,11 +15,6 @@ git commit -m "2" touch 3.txt git add 3.txt -echo "#! /usr/bin/env bash" > 'test.sh' -echo 'echo "Running tests on commit $(git rev-parse --short HEAD)"' >> 'test.sh' -echo "echo 'One failing test'" >> 'test.sh' -echo "exit 1" >> 'test.sh' -git add 'test.sh' git commit -m "3" touch 4.txt @@ -36,15 +23,8 @@ git commit -m "4" touch 5.txt git add 5.txt -echo "#! /usr/bin/env bash" > 'test.sh' -echo 'echo "Running tests on commit $(git rev-parse --short HEAD)"' >> 'test.sh' -echo "echo 'all tests pass'" >> 'test.sh' -echo "exit 0" >> 'test.sh' -git add 'test.sh' git commit -m "5" touch 6.txt git add 6.txt git commit -m "6" - - diff --git a/rebase-exec/verify.ps1 b/rebase-exec/verify.ps1 deleted file mode 100644 index d1992c07..00000000 --- a/rebase-exec/verify.ps1 +++ /dev/null @@ -1,10 +0,0 @@ -Push-Location exercise - -if ($(git log -p master) -match 'exit 1') { - Write-Output "You might have things to fix ask a trainer for help." -} -else { - Write-Output "You are done" -} - -Pop-Location diff --git a/rebase-exec/verify.sh b/rebase-exec/verify.sh deleted file mode 100644 index 136771bf..00000000 --- a/rebase-exec/verify.sh +++ /dev/null @@ -1,8 +0,0 @@ -#! /usr/bin/env bash - -cd exercise -if git log -p master | grep -q "exit 1"; then - echo "You might have things to fix ask a trainer for help." -else - echo "You are done" -fi From 1c278094a13e4c2ae88a91a3da42fb48e101c304 Mon Sep 17 00:00:00 2001 From: Chandan-Chainani Date: Thu, 3 Oct 2024 15:52:01 +0530 Subject: [PATCH 2/2] [Rebase-Exec] README grammer as per suggestion --- rebase-exec/README.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/rebase-exec/README.md b/rebase-exec/README.md index a262dcb6..c39d4762 100644 --- a/rebase-exec/README.md +++ b/rebase-exec/README.md @@ -9,16 +9,24 @@ ### Example 1: Adding content to file in last 3 commits using `git rebase -i --exec HEAD~3`. -1. Run `git log --patch` command to see what changes are include in last commit. -2. Run `git rebase -i --exec "echo '1' >> 4.txt && git add 4.txt && git commit --amend --no-edit" HEAD~3` command it will open configured editor with information what command will be executed for each commits which is notified by `exec ` you can either modify the command or save and exit the editor to let the command run for that specific commit. -3. Run `git log --patch` command to see what are the changes in commits. +1. Run the `git log --patch` command to see what changes are included in the last commit. +2. Run the following command: + ``` + git rebase -i --exec "echo '1' >> 4.txt && git add 4.txt && git commit --amend --no-edit" HEAD~3 + ``` + This will open a configured editor with information about what command will be executed for each commit, notified by `exec `. You can either modify the command or save and exit the editor to let the command run for that specific commit. +3. Run the `git log --patch` command to see what the changes are in the commits. ### Example 2: Change the author for all the commits using `git rebase -i --exec`. -1. Run `git log --format="commit: %H%nauthor: %an%n"` command to see detail related to commit and author. -2. Run `git rebase -i --root --exec "git commit --amend --author='my name ' --no-edit"` command it will open configured editor with information what command will be executed for each commits which is notified by `exec ` you can either modify the command or save and exit the editor to let the command run for that specific commit. -3. Run `git log --format="commit: %H%nauthor: %an%n"` command to see the changes author information for the commits. +1. Run the `git log --format="commit: %H%nauthor: %an%n"` command to see details related to the commit and author. +2. Run the following command: + ``` + git rebase -i --root --exec "git commit --amend --author='my name ' --no-edit" + ``` + This will open a configured editor with information about what command will be executed for each commit, notified by `exec `. You can either modify the command or save and exit the editor to let the command run for that specific commit. +3. Run the `git log --format="commit: %H%nauthor: %an%n"` command to see the changes in the author information for the commits. ## Useful commands