0

I have committed a lot of changes into my local repository but I want to push only few of them. Is it possible? I have a list (before push) with all my changes, but I need to push only few. I would like to revert all this changes from my local repostitory. I created patches with only changes I want to push but now I cannot remove changes from my local repo. I tried to use git reset hard but it does not work as I want.

Developus
  • 1,400
  • 2
  • 14
  • 50
  • Possible duplicate of [how do you push only some of your local git commits?](http://stackoverflow.com/questions/604399/how-do-you-push-only-some-of-your-local-git-commits) – sigy Jan 13 '17 at 10:34
  • Also related: [git - pushing specific commit](https://stackoverflow.com/questions/3230074/git-pushing-specific-commit) – sigy Jan 13 '17 at 10:36
  • @sigy I think OP's problem is different since they also want to change their local history – Dunno Jan 13 '17 at 10:37
  • @Dunno As I understood it OP only wants to revert to then be able to push, but you might be right. Maybe OP can clarify? – sigy Jan 13 '17 at 10:39
  • Yes, I want to push only few changes from my local repo. Not everything, so the link you gave can help me. – Developus Jan 13 '17 at 10:41

1 Answers1

2

If you really, really just want to delete unwanted commits, then do

git rebase -i <sha_of_commit_before_those_that_are_unwanted>

and then delete lines with commits you want to get rid of.

However, bear in mind that those commit will disappear and getting them back might not be possible. Maybe push those commits to a temporary remote branch first, or make a local branch with them?

Now that you've gotten rid of your commits, you can do a simple git push origin branch

Dunno
  • 3,632
  • 3
  • 28
  • 43
  • Well, if I create a temporary branch and commit changes from local repo to this branch than it should resolve my problem, am I right? It is a safe way I think. – Developus Jan 13 '17 at 10:38
  • 1
    @allocer yes, making a local branch will also preserve your commits. I just prefer pushing to remote for additional safety – Dunno Jan 13 '17 at 10:43
  • I've created new local branch, push there all my changes, back to main branch and open Push window. The local changes are still there like before. How to resolve this? – Developus Jan 13 '17 at 12:42