The `git dedicate` command is employed to ensure any improvements carried out in the repository, and the git keeps the history of each and every dedicated undertaking. At times the consumer desires to adjust the dedicated information in advance of or just after publishing the repository. The consumer calls for to rewrite the git heritage to change the older or newer commit of the repository. The –amend alternative is utilised with the `git dedicate` command to rewrite the git record. This tutorial describes how this alternative can be used to the nearby and distant git repository to transform the git commit or git commit message.
Put in GitHub Desktop.
GitHub Desktop aids the git user to complete the git-linked tasks graphically. You can conveniently download the most current installer of this application for Ubuntu from github.com. You have to put in and configure this application soon after download to use it. You can also examine the tutorial for putting in GitHub Desktop on Ubuntu to know the set up procedure properly.
Build a GitHub account
You will demand to develop a GitHub account to check the output of the commands in the distant server.
Build a community and distant repository
You have to create a local repository and publish the repository in the distant server to exam the instructions used in this tutorial. Go to the area repository folder to verify the commands made use of in this tutorial.
Change the last commit:
You have to verify the latest position of the neighborhood repository and do some commit responsibilities prior to making use of any transform to the final dedicate. A area repository named e-book-keep has been utilized to check the commands employed in this tutorial. Run the adhering to command from the repository place to check the present commit position of the repository.
The adhering to output shows that there are two untracked information named booklist.php and booktype.php.
Operate the subsequent instructions to insert two files in the repository with the dedicate message and check the position of the repository soon after commit.
$ git dedicate -m “booklist file has additional.”
$ git include booktype.php
$ git commit -m “booktype file has extra.”
$ git commit
The following output shows that booklist.php and booktype.php files are included with dedicate messages. Upcoming, when the output of the commit command exhibits that the functioning tree is cleanse.
You can alter the past dedicate message by using the editor or executing the terminal’s command. Run the following `git commit` command with –amend option to improve the last dedicate information applying a text editor.
The subsequent editor will open up right after executing the above command to modify the past dedicate message.
Run the pursuing command to change the last commit concept from the terminal.
$ git commit –amend -m “The booktype file has altered yet again.”
The output displays that the very last dedicate information has changed to “The booktype file has changed yet again.”
Transform the previous dedicate:
The older dedicate or the numerous commits can be changed applying the `git rebase` and the `git dedicate –amend` commands. The rebase command is applied to rewrite the commit record, but it is not recommended to use it for all those commits released by now on the remote server. The rebase command is utilised with the quantity of commits to transform the a number of git commits. Run the next command to adjust the last two dedicate messages. The editor will be opened with the final two commit messages after executing the command.
The following output exhibits the very last two commit messages of the repository with commit SHA values.
Generate reword in area of decide on on individuals strains of the commit concept that you want to change. In the pursuing impression, the modification has been finished for just one dedicate only. This dedicate message will be opened for editing on another editor after conserving the present-day file.
The commit concept can be improved from the editor now. In this article, the message, “The booklist file has extra.” has improved to “The booklist file has adjusted.”
If you operate the rebase command once again, you will see the transformed dedicate information in the editor like the subsequent impression.
Add modifications to the previous dedicate:
Suppose the booklist.php file has been modified after committing to the repository. Now, run the next command to re-incorporate the file yet again and improve the dedicate message for this addition by working with the `git commit` command with the –amend possibility.
$ git commit –amend -m “The booklist file has updated.”
The following output will appear after executing the earlier mentioned commands.
If you really don’t want to improve the past dedicate concept just after adding the file all over again, you have to use the –no-edit choice with the –amend selection with the `git commit` command. The pursuing command will include the modified file to the repository without the need of altering the dedicate message.
$ git dedicate –amend –no-edit
Soon after completing all changes in the nearby repository, you can press the nearby articles to the distant server by executing the thrust command from the terminal or by opening the repository in the GitHub Desktop application. Suppose you open up the repository on the GitHub desktop and simply click on the Publish repository possibility. In that situation, the following dialog box will look to publish the modified content material of the community repository to the remote server.
The uses of the –amend possibility for changing a person or far more git commits have been described in this tutorial by employing a demo repository. The way to improve the dedicate with or without having transforming the commit message has been demonstrated in this article to support the git person to fully grasp the objective of employing the –amend choice and apply it in the git repository to alter the commit.