Information

Author(s) Mathieu Jadin
Deadline No deadline
Submission limit No limitation

Sign in

Git Disaster Scenario 1 - Cancel an unpushed commit

The main interest of keeping a modification history is to be able to roll back mistakes. For instance:

https://inginious.org/course/git/git_catastrophy_scenario_1/git-error.svg

If the commit is not yet pushed in the remote repository, that's easy. You can reset or revert the modifications.

The first method will delete the commit(s) of the history. It is only valid if you want to remove the last commit(s) but it is the cleanest one. Note that this command can modify the code if you use the option --hard (so be careful when you use it).

https://inginious.org/course/git/git_catastrophy_scenario_1/git-reset.svg

Let's image that your mistake is in the middle of valid commits.

https://inginious.org/course/git/git_catastrophy_scenario_1/git-error-middle.svg

In this case, the best option is to use revert to cancel the bad commit. Indeed, this will create an additional commit which will cancel the modifications of the bad commit. Note that you cannot have pending modifications while using this method to make it work.

https://inginious.org/course/git/git_catastrophy_scenario_1/git-revert.svg

The corresponding bash command are git reset (documentation) and git revert (documentation).


Question 1: Reset a commit

Download the archive which already contains a cloned repository in the subfolder clone. Use a reset to remove the last commit without deleting the modification in the code or in the staging zone.

After that, re-archive the complete folder and upload it.

Your submission have to have the following hierarchy:

git-commit/
├── bare.git/
|   └── [...]
└── clone/
    └── [...]

Max file size: 1.0 MiB
Allowed extensions: .zip
Question 2: Revert a commit

Download the archive which already contains a cloned repository in the subfolder clone. Use a revert to cancel the before last commit modifications without deleting the commit.

The commit message have to be "REVERT".

Your submission needs to respect the following hierarchy:

git-branch/
├── bare.git/
|   └── [...]
└── clone/
    └── [...]

Max file size: 1.0 MiB
Allowed extensions: .zip