2

I've made some commits and then reverted them. How do I revert the revert? (After my revert there are other commits on the branch). If I remerge my branch into master I get already updated because it already includes all of those commits I suppose.

* b1e0603 - other commit 
* f835cec - Revert "" 
* 68ffc84 - Revert ""
* da5795b - Revert ""
* 75ae2a0 - Revert ""
*   4e51f8f - Merge branch 'master'
|\  
| * 58a6fe8 - commit
* |   205f2a2 - Merge branch 'on this branch are my commits that weere reverted'
|\ \  
| |/  
|/|   
| * 425d6f3 - commit
* |   0efc0e9 - Merge branch 'on this branch are my commits that weere reverted'

Doing git revert 75ae2a0 ouputs conflicts. And there are like 10 reverts that I have to run. Should I just revert the merge (205f2a2)?

Thanks!

Claudiu Creanga
  • 8,031
  • 10
  • 71
  • 110
  • The best solution depends on what state you ultimately want to be in. One option might be to create a new branch, cherry pick the commits you actually want, reset `master` to an earlier state, *then* merge your new branch into `master`, essentially abandoning the messy history containing the revert commits. – chepner Apr 07 '15 at 15:59
  • Did you push your changes to the public repository? If not then you can rewrite your changes. Otherwise it might be more complicated and may require more revert/merge works – Amnon Shochot Apr 07 '15 at 16:00
  • @AmnonShochot didn't push my changes. if I just open and resave all my affected documents will it be enough? Thanks – Claudiu Creanga Apr 07 '15 at 16:02
  • Opening and resaving documents is a completely separate issue from your repository's revision history. – chepner Apr 07 '15 at 16:03
  • If you did not push your changes then you can: (1) backup your repo (2) reset/revert your changes (the one simpler for your case) and re-apply the changes you're interested in – Amnon Shochot Apr 07 '15 at 16:04

1 Answers1

1

Summarizing the discussion above, as you did not push your changes you can re-write you changes with git reset/revert (depends on your specific case).

You can find some great tutorials about your options here in Atlassian Git Tutorials, and specifically in chapters Undoing Changes that discuss your options with git checkout, reset and revert commands, and Reset, Checkout, and Revert that discusses these command both in commit level and file level.

One recommendation, though - as some of these commands are irreversible I'd recommend you to make a backup of your repo and current commits so in case something will get wrong you will have a backup of your changes.

Amnon Shochot
  • 8,998
  • 4
  • 24
  • 30