Redoing Git History - AD-EYE/AD-EYE_Core GitHub Wiki
Sometimes one needs to redo the history of the branch without changing the history already in Github (i.e., changing the commits messages already in the server). Note that you should never amend the commits in Github, as the purpose of the repository is to keep the history intact.
Below you can find two examples where this situation arises:
- Changing between AD-EYE computers requires updating the git credentials, in particular the name and email of the developer. When this does not happen, the branch ends up having git commits with the wrong developer name.
- When commit messages do not follow the right conventions (such as lack of descriptiveness).
Therefore, one way to solve this issue is
- Go back in history to a previous commit where the issue started using the following command:
git reset --soft a5bb4a58f213ec4d2783f83e1c321b5387c1845c
where a5bb4a58f213ec4d2783f83e1c321b5387c1845c
is the commit_ID (that can be checked with the git log
).
- Create a new branch from that point in history:
git checkout -b <new_branch>
- Delete any files from the git repository (but not from the computer!):
git rm --cached File
- Start committing desired files and writing new (desired) history:
git add <just the needed files>
git commit