0

I made some changes inside ServiceImpl.java and when i was about to commit in repository it shows me you had some changes in .project file. The changes are...

<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
    </buildCommand>
     <buildCommand>

and by mistake I commited it in repository, And I saw some conflict error.
I removed the code from project` file! and recommit it, and i saw the same error again!

The problem is I have done many commits since then.
How would I cancel this faulty commit?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Akash
  • 816
  • 3
  • 13
  • 38
  • can you revert it back ? – Sanjay Rabari Apr 17 '14 at 07:02
  • yeah i want to revert it back... i used git reset --hard HEAD but it brings me at last commit. any other way to solve this problem – Akash Apr 17 '14 at 07:05
  • @VonC While merging code in GIT (Bitbucket), after pull request I got an issue src/main/webapp/css/main.css (conflicts) the code is fine in Eclipse but in Bitbucket view its showing 3 more lines added in code having some text. like <<<<<<< destination:f27cd37fb7008c0d18f63514ca44ceacbaa3c658 ============================ >>>>>>> source:95de515e0203585db3c4f1084e37ade6dcc08ed2 when i try to edit it the appear line becomes disappear :( – Akash Apr 29 '14 at 13:14
  • @Akash Yes, I saw http://stackoverflow.com/a/23358089/6309, but if this is a BitBucket editor feature, I would first clone that BitBucket repo locally, and open in a simple text editor that filr, to see if those merge merkers are still there. Then choose the part you want to keep, remove the merge markers, add, commit and push back. – VonC Apr 29 '14 at 13:16
  • VonC i am still unable to resolve this i tried everything :-/ I would be very thankful if you help me :( as i wasted too much time on this. i can give you my teamviewer credential :-/ – Akash Apr 29 '14 at 13:27

1 Answers1

0

If your commit consisted of only the one file, you could do a:

git reset --hard HEAD~

That will bring you back to the state before your last commit.

Make sure you don't have any other modifications in progress though (or stash them first).


The OP Akash adds though in the comments:

i did commit manytimes

You have tow choices:

  • a git rebase --interactive let you reorder past commits, including dropping the one you don't want.
    That changes the history though, meaning you will need a git push -force (if you did already push those commits before): if you are pushing to a pull request branch, this ok. If you are pushing to a public branch (cloned by other), that can be problematic.

  • a git revert (see "Revert to previous Git commit"), in order to create a new commit which will cancel the modification of the past commit.
    This is safer, and doesn't change the history.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks VonC but as i mentiond i want to bring myself at last merged code! any suggetion? – Akash Apr 17 '14 at 07:14
  • @Akash did you use the reset eventually? – VonC Apr 17 '14 at 07:45
  • My situation is, i am new to bitbucket... last night i made some changes in java code and at the time of commit, it shows me you have changed 2 file one is java and another one is .project, by mistake i pulled the request for both files. after ward i got some confliction error, and i reset the code as it was! i tried to recommit it. it commited successfully and i pulled request for them. i know i did some stupid stuffs Please help:-/ @VonC – Akash Apr 17 '14 at 07:54
  • @Akash so the reset could help, in order for you to redo your changes, no? (I mean, you did mark the answer as "valid") – VonC Apr 17 '14 at 07:55
  • As far i think, reset brings you to the previous commit? and i did commit manytimes @VonC any help – Akash Apr 17 '14 at 08:03
  • @Akash Ok. I have completed the answer in order to present the two choices you have. – VonC Apr 17 '14 at 08:48
  • @Akash see also http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.html – VonC Apr 17 '14 at 08:50