How to disable changes using git

I use the git stream, and without hesitation, I executed the code with the wrong branch (function), and then published it.

I need to take this code, remove it from say, branch 1 and move it to the correct branch, which is branch 2.

All files are stored in one folder, which can make a lot much easier, I just don’t know how to do it.

eg.

Branch 1 { Commit That contains { ./path/to/files_that_should_be_here ./path/to/files_that_need_to_be_in_branch_2 } } Branch 2 { No Commits. } 
+4
source share
2 answers

to move commit to proper use of branches

 git cherry-pick commithash 

in the branch you want to move the commit to.

And remove the commit from this branch use

 git reset --hard HEAD~1 
+1
source

If you have not posted your change, the easiest way to do this is to kill the last commit in branch1 (note: this will completely destroy everything that the last commit entered):

 git checkout branch1 git reset --hard HEAD~ 

then check for the correct branching and copy your change there.

If you posted the change, you can still kill the last commit, but then you will have to git push --force , which you may not have permission, and even if you did, it can cause a lot of grief for other users of this repository.

Instead, you should simply return the wrong change:

 git revert <bad_commit> 

and repeat it in the correct branch.

+5
source

All Articles