Git: Undo A Commit After Several Good Commits Have Been Commited Afterwards
I have a beginner question around git and GitHub i was hoping someone could help with.
I have accidentally committed a change in piece of code that contains credentials on my local private repository on my local machine.
My pseudo commit history looks like the below and i am using the desktop application for GitHub to make these commits. I made the mistaken commit at id 3 but then all my other commits from four to seven are a big body of work and I do not wish to lose them.
Since this is my own repository the quick method might be to simply copy out the files i changed and revert back all my changes to id 3 and then copy in my good changed files. I was wondering if there was a better
commit first change id 1 commit second change id 2 commit third change id 3 - here is where the password was committed commit first change id 4 commit second change id 5 commit first change id 6 commit second change id 7
Thank you very much for your time
You either can do squash:
git rebase -i <commit_id or HEAD~5> # move your cursor on the commit line & delete that commit by pressing double `d` git push -f origin <branch>
It helps to delete selected commits only, without changing commits after and before that commit.
Or, soft reset and commit:
git reset --soft <commit_id or HEAD~5> git add . git commit -m "<message>" git push -f origin <branch>
It deletes all commits from the
commit_id or HEAD~5 and makes a single commit.
- → Authenticate with a cookie using laravel 5.1 and jwt
- → Finding a specific GitLab tag from PHP
- → React: How to publish page on server using React-starter-kit
- → babel-loader, webpack, ES2015 modules: "Element type is invalid"
- → Create a function-attribute of a function, which is, in its turn, a method of an object literal
- → Model Validation in laravel 5.1 not working
- → GIT fatal: loose object
- → Laravel validation required rule not working
- → Axios array map callback
- → Where does this `webpack://` come from for `webpack-dev-middleware`?
- → error when trying to modify project in laravel forge
- → GitHub Pages and Jekyll content duplication and SEO issues
- → Use Laravel repositories with Datatables