Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - exclude specific commit and push

How to exclude specific commit from series of commits. I mean if I have 5 commits, and I only want to push 4 commits. How to do this. Please help to resolve this.

like image 472
Ved Avatar asked Mar 20 '16 10:03

Ved


1 Answers

You will need to have a new branch with the desired commits.

You can do it in several ways


git cherry-pick

Checkout a new branch to the specific sha-1 you want to start from:

git checkout <origin branch>
git checkout -b <new branch>

# now cherry-pick the desired commits onto the new branch
git cherry-pick commit1 commit2 ... commitN

# now push to remote
git push origin remote <branch name>

Other options:

git revert

git revert SHA-1

Use git revert to undo the changes you have made in the unwanted commit, the result will be branch with the old code and the new code but the current state will be the original code


git rebase -i

Interactive rebase. choose the commit you don't want and remove it.

# X is the number of commits you wish to squash
git rebase -i HEAD~X

Once you squash your commits - choose the e for edit and place the code you want it to be, add and commit

enter image description here


git filter-branch

Filter branch can be used to filter any content you want.

git filter-branch --env-filter '<do what ever you want on this commit range' SHA1..SHA1
like image 125
CodeWizard Avatar answered Sep 28 '22 04:09

CodeWizard