Guest User

Untitled

a guest
Apr 25th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. Ever need to remove something sensitive from github?
  2.  
  3. Ensure you have a latest copy of the repo with the mess up first before removing a commit way back when!
  4.  
  5. 1 - Copy the commit reference you like to go back to from the log:
  6.  
  7. ```
  8. git log
  9. ```
  10.  
  11. 2 - Reset git to the commit reference:
  12.  
  13. ```
  14. git reset <commit_ref>
  15. ```
  16. 3 - Stash/store the local changes from the wrong commit to use later after pushing to remote:
  17.  
  18. ```
  19. git stash
  20. ```
  21. 4 - Push the changes to remote repository, (-f or --force):
  22. ```
  23. git push -f
  24. ```
  25.  
  26. 5 - Get back the stored changes to local repository:
  27. ```
  28. git stash apply
  29. ```
  30.  
  31. 7 - In case you have untracked/new files in the changes, you need to add them to git before committing:
  32.  
  33. ```
  34. git add .
  35. ```
  36. 6 - Add whatever extra changes you need, then commit the needed files, (or use a dot '.' instead of stating each file name, to commit all files in the local repository:
  37.  
  38. ```
  39. git commit -m "<new_commit_message>" <file1> <file2> ...
  40. ```
  41.  
  42. or
  43.  
  44. ```
  45. git commit -m "<new_commit_message>" .
  46. ```
Add Comment
Please, Sign In to add comment