- You were trying out something and it did not work as planed.
- You were using a new version of a library and it has bugs in it.
- You made changes that were not needed and what to just go back to an old version.
In the end, the result is the same, you have changes that you made and now you want to get rid of them.
If you are using a Code Management System, what you'll need to is a subtractive merge. A subtractive merge is a way to remove or undo changes.
Say you have the following Ruby code
Version 1:
# Hello World program in Ruby
puts "Hello World"
Version 2:
# Hello World program in Ruby
puts "Good Bye World"
Version 3:
# Hello World program in Ruby
puts "Good Bye World"
puts "Hello world again"
Say you are currently at the third version of code ("Hello world again") and you want to go back to the first version of the code ("Hello World"), what you'll need to do is subtractive merge back to the first version of the code.
The way to think of a subtractive merge is that you are removing changes that were done. In the case of doing a subtractive merge back to version 1, creating a new version 4 of the code we will have the following for version 4 of our code:
Version 4:
# Hello World program in Ruby
puts "Hello World"
Example in ClearCase:
To do this in ClearCase from the command line you would do the following:
cleartool merge -to filename -delete -ver \main\branch\versionNumber \main\branch\versionNumber
Example with file hello.rb in the \main\dev stream:
cleartool merge -to hello.rb -delete -ver \main\dev\2 \main\dev\3
Next time you find yourself wanting to rollback or undo changes, try a subtractive merge.