github - Remove a git commit between two commits -


i added functionality in project took 4 git commits, business asking functionality no more needed(after more month). need remove particular git commit(s) repo has 27 more commits after that.

there 4 ways of doing so:

  • clean way, reverting keep in log revert:

    git revert --strategy resolve <commit> 
  • harsh way, remove altogether last commit:

    git reset --soft "head^" 
  • rebase (show log of last 5 commits , delete lines don't want, or reorder, or squash multiple commits in one, or else want, versatile tool):

    git rebase -i head~5 

and if mistake done:

git rebase --abort 
  • quick rebase: remove specific commit using id:

    git rebase --onto commit-id^ commit-id 
  • alternatives: try:

    git cherry-pick commit-id 
  • yet alternative:

    git revert --no-commit 
  • as last resort, if need full freedom of history editing (eg, because git don't allow edit want to), can use very fast open source application: reposurgeon.

note: of course, these changes done locally, should git push afterwards apply changes remote. , in case repo doesn't want remove commit ("no fast-forward allowed", happens when want remove commit pushed), can use git push -f force push changes.

note2: if working on branch , need force push, should absolutely avoid git push --force because may overwrite other branches (if have done changes in them, if current checkout on branch). prefer always specify remote branch when force push: git push --force origin your_branch.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -