# Committing

## Overview

A commit is the basic operation of Git version history. It is basically a local snapshot of your repository at a particular point in time. It's a good idea to create new commits frequently, similar to saving changes as you write a document.  You can choose to [Push ](https://docs.copia.io/docs/git-based-source-control/basic/making-changes/pushing)these commits to the server at any time.

{% hint style="warning" %}
Copia has a 2 GB max file size for pushing files to the server.  This means you should not commit any files over 2 GB in your repository.&#x20;
{% endhint %}

A commit includes a commit message and description of the change, along with information about when the change occurred and who made it.

There are two sections in this topic:

* [Committing in the Web App](#committing-in-the-web-app)
* [Committing in the Desktop App](#committing-in-the-desktop-app)

We will start with committing in the Web App, but click the link above to jump to the Desktop App section if needed.

## Committing in the Web App

### Adding a file <a href="#creating-a-file-in-your-browser" id="creating-a-file-in-your-browser"></a>

From the home page, navigate to the repository you want to add a file to. Click on the *New File* button.

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2FYHPZWZl5xpceVuJghNhY%2FWebApp_NewFile.png?alt=media\&token=de2ffe00-6559-4d3c-8e82-f036856d97a5)

On the next screen, you can name your new file. This will be added to the repository.

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2FU2pNvp8mL0xvexTNZnVp%2FWebApp_NameNewFile.png?alt=media\&token=c83db172-df54-40e5-b3f7-111587193fcf)

Scroll down to the bottom of the screen to commit your file. At this point, you can choose whether to commit the file to `main` or to create a new branch for this file.

Click *Commit Changes* to finish creating your file.

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2F9O2JiXs1OW0gmec4dtKH%2FWebApp_CommitNewFile.png?alt=media\&token=0a7346fd-7b27-42e6-8fc4-88fe9b7c4f9a)

### Uploading a File <a href="#uploading-a-file-in-your-browser" id="uploading-a-file-in-your-browser"></a>

From the home page, navigate to the repository you want to upload a file to. Click the *Upload File* button.

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2FdncZDZUFKahZBaLwLJ1j%2FWebApp_UploadFile.png?alt=media\&token=fcef15ac-8d4e-4b04-b72b-e6141effb138)

To upload the file to a specific folder within the repo, you can type the folder name in the "Add a directory..." input. Then drag and drop your file into the upload field, or click on the box to browse and select the file you wish to upload.

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2FeCYSm68XR4tt2RpFybXU%2FWebApp_NameUploadFile.png?alt=media\&token=f455b918-f173-436c-a43d-dffd1e556ce1)

Scroll down to add an optional description of the file you have uploaded and commit your file to the directory you have chosen. At this point, you can choose whether to commit the file to `main` or to create a new branch for this file.

Click *Commit Changes* to finish creating your file.

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2F85AdmuiTETDSSRHxqeH1%2FWebApp_CommitUploadFile.png?alt=media\&token=8cecb794-0f91-4c7d-8aa3-fc515ca33283)

## Committing in the Desktop App

### Making a Change <a href="#make-a-change" id="make-a-change"></a>

Click *Show in Explorer* to manage your local repository.

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2F47aQ4Lgi5Hx10Bk3nAPH%2FDesktopApp_ShowInExplorer02.png?alt=media\&token=d7e79bbf-84ff-461b-8d21-268c2f0447c9)

Your file manager will display all the contents of your repository. You can make changes to your file, rename it, or delete it entirely. When you reopen the Desktop App, you will be presented with the reflected change(s) in the *Changes* tab.

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2FUGxym0b4GN2aWJeyl1rC%2FDesktopApp_Diff.png?alt=media\&token=49354efb-8b96-4a0d-8bba-32cd8d4062e1)

{% hint style="info" %}
If you don't see your changes reflected in the Copia Desktop App, first make sure that you successfully saved your file.
{% endhint %}

If you realize you made a mistake, you can always discard your changes prior to committing them. To do this, navigate to the *Changes* tab, right-click on the change you wish to discard, and select the *Discard changes...* option.

<figure><img src="https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2FVY1kh7m8s11CeOieV82o%2FDesktopApp_Diff_DiscardChanges.png?alt=media&#x26;token=fa9967ce-cc51-419c-918f-d2c087faa1f4" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Discarding changes will change the local file on your computer back to the previous version. Ensure that you are certain of this before discarding changes.
{% endhint %}

Copia recommends that you perform file renames separate from file changes. This is because Git only infers a rename operation based on whether a newly added file is similar to another file that was deleted. Simultaneously making changes and renaming in a single commit may result in the end of one file history and the start of a new one.

## Commits <a href="#commit--push-a-change" id="commit--push-a-change"></a>

### Committing a Change

Commits are often used to mark significant changes that you might want to look back on. You can think of them as meaningful, local changes that you can choose to store as a checkpoint. All commits you make will appear in the version history.

{% hint style="info" %}
Commits that are especially significant can be used to create a tag. To learn more, check out the [Tags and Releases](https://docs.copia.io/docs/git-based-source-control/additional-features/tags-and-releases) section.
{% endhint %}

Once you're ready to commit in the Desktop App, navigate to the *Changes* tab and fill in the *Summary* and *Description* fields with information that outlines the changes reflected in that commit. The *Description* field is optional.

<figure><img src="https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2FbvY8unB2K30I84CoaOcz%2FDesktopApp_CommitDetails.png?alt=media&#x26;token=08a55c2d-3989-4080-96ec-235d8deca6e3" alt=""><figcaption></figcaption></figure>

If you'd like to add a Co-Author to the commit, click on the icon in the lower left of the *Description* field. You might do this in certain use-cases where two engineers are working on code, but only one is saving changes to Copia. This allows you to attribute code changes to multiple users for future reference.

<figure><img src="https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2FqS0NIVZhLBDeOtqxzCTf%2FDesktopApp_CommitAuthors.png?alt=media&#x26;token=7f68bc2d-8775-42a2-81f8-036c63733009" alt=""><figcaption></figcaption></figure>

Press the *Commit to main* button. This will store your change locally. You can make multiple changes and commit them before moving on.

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2Fh9U8pKUJp85NwnYvJh6l%2FDesktopApp_CommitPress.png?alt=media\&token=52b7820f-bae0-40de-824e-27b357813aab)

{% hint style="info" %}
While you can commit a single change and push it to remote, it's quite common to make multiple meaningful commits on your local branch and then push. To learn more about pushing commits, check out the [Pushing](https://docs.copia.io/docs/git-based-source-control/basic/making-changes/pushing) section.
{% endhint %}

### Amending a Commit (Amend Commit)

If you need to update a commit message or if you forgot to include changes in your commit, you might want to amend your commit. This action updates the most recent commit you have made in your current branch, prior to pushing the change.

To amend a commit, navigate to the *History* tab and right click on the most recent commit.

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2Fe8GB6RyJockkrcjd8fb1%2FDesktopApp_ViewHistory_AmendCommit.png?alt=media\&token=7e87f474-c8c8-48ec-a593-6aac145bc1d8)

{% hint style="info" %}
If you wanted to include additional changes, make them prior to amending the commit.
{% endhint %}

Update the *Summary* and *Description* fields to clarify the reason for the amend. Be sure to check any uncommitted changes that you would like to add to the commit. When finished, click the *Amend last commit* button.

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2FcSepnPDqIQPs84DvNKzO%2FDesktopApp_Diff_AmendDetails.png?alt=media\&token=7b7f1201-81f2-4aa1-979d-87a66ee12320)

{% hint style="warning" %}
You cannot amend a commit if you have already pushed a change. Doing so would alter the history on the Copia server and cause confusion for others who may have already pulled these changes.
{% endhint %}

### Reverting a Commit (Revert Changes in a Commit)

In addition to amending a commit, you might want to revert a specific change. This allows you to remove that change from the top of the main branch.

Navigate to the *History* tab, right-click the commit you want to revert, and choose the *Revert Changes in Commit* button.

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2F8n6aBdGIjuYUSxzuv7xh%2FDesktopApp_ViewHistory_RevertCommit.png?alt=media\&token=c9687dfd-0307-4fe2-8e4f-083125d63616)

{% hint style="info" %}
If you experience issues with reverting, first ensure that your IDE is closed.
{% endhint %}

Push the revert to remote by clicking the *Push* button. You can learn more about pushing in the [next section](https://docs.copia.io/docs/git-based-source-control/basic/making-changes/pushing).

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2FDKunZO8zuVHnqh1YlcGh%2FDesktopApp_ViewHistory_RevertCommitPush.png?alt=media\&token=fe0b29aa-004e-45f4-a18a-f40b76a0229b)

{% hint style="info" %}
You can only perform a revert after pushing if no subsequent commits have been performed.
{% endhint %}

If you require more guidance, we recommend that you review our video on reverting:

{% embed url="<https://www.youtube.com/watch?v=8a84wVlQuPI>" %}

### Retrieving a Commit (Checkout Commit) <a href="#revert-change-desktop" id="revert-change-desktop"></a>

If you would like to access the files of a previous commit, you can use the *Checkout Commit* feature.

Before using this feature, make sure that you don't have any repository files open. Click into the *History* tab, right click on your commit, and select the *Checkout commit* option.

![](https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2FDhu9LsVYhKOtyUYJioqj%2FDesktopApp_ViewHistory_CheckoutCommit.png?alt=media\&token=b09b5a89-20ef-4e7c-9112-d46bbadc1c24)

When you select this option, you revert to an older commit, meaning that your repository files and commit history will be temporarily reverted to the prior state. This state in Git is called a "Detached HEAD" and is treated as a temporary local branch. At this point, you can access your local repository and it will reflect the files at that commit point.

You can use this method to revert files to a prior state (or just for review) by either:

1. **Making a copy of those files to later commit**

   *After copying the files to another location, you can cancel the Checkout by just switching back to the Main branch from the dropdown.*\\
2. **Creating a new Branch from the Detached Head and merging**

   *In the Branch dropdown, select the "New Branch" option, which will use the Detached HEAD as the revision for the new branch*

To cancel the entire Checkout operation, simply switch back to the Main branch from the *Branch* dropdown.

If you require more guidance, we recommend that you review our video on commit checkout:

{% embed url="<https://www.youtube.com/watch?v=RQb7ysUKjOg>" %}

### Restoring a Previous Commit (Restore from Commit)

If you would like to restore the files of a previous commit, you can use the *Restore from Commit* feature.

Click into the *History* tab, right-click on your commit, and select the *Restore from Commit* option.

<figure><img src="https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2Fz1FtJqDSxgqXXD16VWon%2FDesktopApp_ViewHistory_RestoreFromCommit.png?alt=media&#x26;token=f609e8a3-fe24-42da-a6e9-85a5fc4d80f9" alt=""><figcaption></figcaption></figure>

If you already had changes in your working directory (i.e. your local repository folder), the Desktop App will warn you before overwriting those changes.

<figure><img src="https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2FnHIprSDTxfqdlkJEHeAm%2FDesktopApp_RestoreAssurance.png?alt=media&#x26;token=7b9c16d5-ad10-484b-92b3-defe757bf166" alt=""><figcaption></figcaption></figure>

Once complete, the restore operation will update your local repository with the files from that previous commit. Navigate to the *Changes* tab and provide information for the *Summary* and *Description* fields. Once ready, press the *Commit* button. Your new commit will be reflected in the *History* tab.

<figure><img src="https://3704730939-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4lSQNVI3DZ15V7kjkMCA%2Fuploads%2FcgLaJlmZTuGEJJbGvne1%2FDesktopApp_Diff_RestoreCommit.png?alt=media&#x26;token=f3369ddf-2c74-43eb-959e-a80e4bbce916" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
We recommend that you incorporate the SHA and date of the prior commit into the commit message for traceability.
{% endhint %}
