_

Always be tactful

Insights (종료)/For EN

[GitHub] Deleting the Most Recent Commit

funczun 2024. 11. 29. 11:29

 All processes are carried out by opening the terminal and entering Git commands. This is the content from deleting commits in the local repository to reflecting changes in the remote repository.

 

Deleting Commits While Keeping Changes
git reset HEAD^

 Deletes the most recent commit

git reset HEAD~n

 Delete the last n commits

Deleting Both Commits and Changes
git reset --hard HEAD^

 Deletes the most recent commit

git reset --hard HEAD~n

 Delete the last n commits

Checking Branches and Reflecting Changes in the Remote Repository
git branch

 You can use this Git command to find out the name of the branch you are working on.

git push origin main --force

 If you are not on the main branch, replace main with the name of your branch.


 Using a force push(--force) alters the history of the remote repository, so it is advisable to avoid using it unless necessary. If you are working on a branch alone, it may not be an issue, but if other team members are working on the same branch, it could affect their work.

728x90