howToEraseCommitLog
This page explains that erase git commit log.
related system
linux, git
How to rollback git commit log?
- clone your git repository
git clone https://gitexample.com/exampleUser/exampleRepository.git
- change directory to download repository.
cd exampleRepository.git
- edit and run this command. please only edit [‘integer_number’] in command.
git reset --hard HEAD~[integer_number]
If you want to rollback to the second previous commit from the last commit, type…
git reset --hard HEAD~2
- push edited commit log to server. [branch-name] is branch name, such as
main
.git push origin [branch-name] --force
Warning!
edit commit log is very dangerous work. This work recommanded when other files are not uploaded since the file you want to delete.
This jobs moves head back as you want. So, you can keep “verified” sign on github.
How to erase specific git commit log?
- clone your git repository
git clone https://gitexample.com/exampleUser/exampleRepository.git
- change directory to download repository.
cd exampleRepository.git
- edit and run this command. please only edit [‘file_path/file_name’] or [‘folder_path’] in command.
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch 'file_path/file_name'" --prune-empty --tag-name-filter cat -- --all
if you want to delete under certain directory, then use this command.
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch -r 'folder_path'" --prune-empty --tag-name-filter cat -- --all
- push edited commit log to server
git push origin --force --all
Warning!
edit commit log is very dangerous work.
--force
options are forced overwriting existing commit log.- This job erase “verified” sign on github.
- Particularly when collaborating, you need to be careful as this may affect other people’s work.
- when you erase the commit log, then existing files also deleted. so you reupload the file after erase commit.
###When This job recommend?
- when git upload files that includes your personal info, secret files, etc.
- when you needed to delete specific file completely.