# How to merge source code files
This article explains how to control file merging in GroupDocs.Comparison for Java.
---
[GroupDocs.Comparison](https://products.groupdocs.com/comparison/java) allows you to merge source code files by using the [ComparisonAction](https://reference.groupdocs.com/comparison/java/com.groupdocs.comparison.result/comparisonaction/) properties:
- [ComparisonAction.ACCEPT](https://reference.groupdocs.com/comparison/java/com.groupdocs.comparison.result/comparisonaction/#ACCEPT) accepts the found changes and adds them to the file without highlighting
- [ComparisonAction.REJECT](https://reference.groupdocs.com/comparison/java/com.groupdocs.comparison.result/comparisonaction/#REJECT) rejects the found changes and removes them from the output file
To apply/reject changes to output file, follow these steps:
1. Instantiate the [Comparer](https://reference.groupdocs.com/comparison/java/com.groupdocs.comparison/comparer) object. Specify the source document path or stream.
2. Call the [add()](https://reference.groupdocs.com/comparison/java/com.groupdocs.comparison/comparer/#add-java.lang.String-) method. Specify the target document path or stream.
3. Call the [compare()](https://reference.groupdocs.com/comparison/java/com.groupdocs.comparison/comparer/#compare-java.lang.String-) method.
4. Call the [getChanges()](https://reference.groupdocs.com/comparison/java/com.groupdocs.comparison/comparer/#getChanges--) method to get changes list.
5. Call the [setComparisonAction()](https://reference.groupdocs.com/comparison/java/com.groupdocs.comparison.result/changeinfo/#setComparisonAction-com.groupdocs.comparison.result.ComparisonAction-) method of the appropriate change object. Specify the [ComparisonAction.ACCEPT](https://reference.groupdocs.com/comparison/java/com.groupdocs.comparison.result/comparisonaction#ACCEPT) or the [ComparisonAction.REJECT](https://reference.groupdocs.com/comparison/java/com.groupdocs.comparison.result/comparisonaction#REJECT) value.
6. Call the [applyChanges()](https://reference.groupdocs.com/comparison/java/com.groupdocs.comparison/comparer/#applyChanges-java.lang.String-com.groupdocs.comparison.options.save.SaveOptions-com.groupdocs.comparison.options.ApplyChangeOptions-) method. Specify the collection of changes.
For example, you need to compare and merge several versions of source code files and to accept or discard changes made by different persons.


The differences show that two methods are in the **source.cs** file: `AddNumbers` and `Sum`.
If you do not use the [ComparisonAction](https://reference.groupdocs.com/comparison/java/com.groupdocs.comparison.result/comparisonaction/) property, all changes are committed to the output file, and these methods are removed. If you need to control the merging of files, the [ComparisonAction](https://reference.groupdocs.com/comparison/java/com.groupdocs.comparison.result/comparisonaction/) property helps you.
The following code snippet shows how to merge two source code files:
{{< tabs "example1">}}
{{< tab "Java" >}}
```java
import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.options.ApplyChangeOptions;
import com.groupdocs.comparison.result.ChangeInfo;
import com.groupdocs.comparison.result.ComparisonAction;
import java.nio.file.Path;
// ...
try (Comparer comparer = new Comparer("source.docx")) {
comparer.add("target.docx");
final Path resultPath = comparer.compare("result.docx");
ChangeInfo[] changes = comparer.getChanges();
for (int i = 0; i < 10; i++) {
changes[i].setComparisonAction(ComparisonAction.ACCEPT);
}
for (int i = 10; i < changes.length; i++) {
changes[i].setComparisonAction(ComparisonAction.REJECT);
}
comparer.applyChanges(resultPath, new ApplyChangeOptions(changes));
}
```
{{< /tab >}}
{{< /tabs >}}
As a result, you get a merged source code file where the deleted elements are marked in **red**, the added – in **blue**, and the modified – in **green**.
Also you receive an HTML file in HTML with changed places in the code.
| Result source code file | Result HTML file |
| ----------------------------------------------------------------------- | ------------------------------------------------------------------------- |
|  |  |
As you can see from the resulting files, only one of the two methods was removed.