-2

I modified one file and did the following:

cd puppet-configuration-prod/
git status
git pull origin master
git add Puppetfile_puppet-prod
git commit -m 'modificaton Omar'
git pull origin master
git push origin master

But this pushed a lot of changes that I didn't want to. Please help to undo the following.

EDIT : Apparently since i haven't update my local repo in a while , i have pulled all the lastest commit and commited them again with my merge... what i should have used is --rebase while pulling.

Omar BISTAMI
  • 770
  • 2
  • 11
  • 19
  • Seriously? What have you tried so far. Hint: You already mentioned it in your title. So please try to put in some self-effort before asking such question. – ckruczek Feb 12 '18 at 09:17
  • Possible duplicate of [How can I remove a commit on GitHub?](https://stackoverflow.com/questions/448919/how-can-i-remove-a-commit-on-github) – phd Feb 12 '18 at 13:36

2 Answers2

1

Are you using a repo shared with other person? If so, you should avoid modifying the changes already push as anybody who has pulled will have history problems if you try and change it. In that case, maybe reverting your latest commit(s) would be the wisest option.

If you do not have such a constraint, you can simply change your master local branch to anything you want and then force a push

git push origin master -f
Axnyff
  • 9,213
  • 4
  • 33
  • 37
  • I'm sharing my repo with 30 people , apparently since i haven't update my local repo in a while , i have pulled all the lastest commit and commited them again with my merge... what i should have used is --rebase while pulling. – Omar BISTAMI Feb 12 '18 at 17:10
1

The safest way to proceed here is to git revert the commit you just pushed:

git revert <SHA-1>

Replace <SHA-1> with the hash from the commit you just made. This will tell Git to make a new commit on the top of your branch which functionally undoes whatever that commit did.

You could try deleting one or more commits, but then you would have to force push your branch out, and this can inconvenience anyone else sharing your branch.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Apparently since i haven't update my local repo in a while , i have pulled all the lastest commit and commited them again with my merge... what i should have used is --rebase while pulling... To get the SHA-1 , i need to do a git log right ? – Omar BISTAMI Feb 12 '18 at 17:11
  • @OmarBISTAMI Yes, `git log` is probably the fastest way. – Tim Biegeleisen Feb 13 '18 at 00:04