| by Arround The Web | No comments

How to Make Amazing Commits Using “git add –interactive” Command

While performing tasks on Git, developers can generate commits that are focused and meaningful with the help of the “git add –interactive” command. Commits can make it easier to understand the changes that users made to the code over time. Additionally, it helps to avoid accidentally including unrelated changes in commits, which can make it easier to track down bugs and troubleshoot issues in the code.

This post has stated the method for making amazing commits with the help of the “git add –interactive” command.

How to Make Amazing Commits Using “git add –interactive” Command?

In Git, the interactive mode is designed for making it easy to manipulate and review all changes in the entire repository. When a user runs the “git add” command along with the “–interactive” option, a list of commands will appear. The description of all commands is mentioned below:

    • status” command is used to determine the current status of the staging area. It also shows how many files are added or removed from the staging index.
    • update” command permits the Git users for staging complete files into the tracking index.
    • revert” command is used to untracked changes from the staging index.
    • add untracked” command is used for adding the untracked files into the staging area.
    • patch” command is used to add the alias for the Git commands.
    • diff” command is used to determine a difference between both the index and HEAD.
    • quit” command is utilized for terminating the interactive mode.
    • help” command is used to display all the information about Git.

To make amazing commits using the “git add –interactive” command, check out the below-given procedure:

    • Redirect to the Git local directory.
    • Generate files with different names.
    • Check the current status to verify the generated files by using the “git status” command.
    • Utilize the “git add –interactive” command to make amazing commits and track the files.

Step 1: Move Git Local Directory

Initially, open the Git bash tool with the help of the Startup menu. Then, navigate to your preferred Git local repository by executing the “cd” command:

cd "C:\Users\user\Git\testproject"

 
Step 2: Generate Files
Next, create multiple files by running the “touch” command:

touch file3.txt file4.txt

 

Step 3: View Status

To verify whether the files are generated or not, use the “git status” command:

git status

 
The resultant output indicates that both files have been created successfully and exist in the Git working area:


Step 4: Make Amazing Commits

Use the “git add –interactive” command to make amazing commits:

git add --interactive

 
After executing the above-given command, a list of commands will be displayed. Users can directly run any command according to their needs by inserting the respective number of the command or the full command name:


We have used the “status” command to check the current state of the repository. However, it shows nothing because the staging area is empty. It will display the status of the Git staging area.

Step 5: Track Files in Staging Area

Insert the “add untracked” beside the “what now>” to track the files from the working area to the staging index:

add untracked

 
Then, we specified the untracked files name, as “file3.txt” and “file4.txt” and hit the “Enter” key. It displayed the tracked files name with the asterisk “*” symbol that represents these files are staged:


Step 6: Verify the Tracked Files

To verify whether the untracked files have been added to the staging area or not, run the provided command:

status

 
It can be noticed that both files have been added successfully:


Step 7: Revert Changes

To revert the changes, use the “revert” command and specify the respected number of the given file that needs to revert:

revert

 
The below-given output indicates that both tracked files have been reverted successfully:


Lastly, run the provided command to terminate this procedure:

quit

 

Conclusion

To make amazing commits using the “git add –interactive” command, first, redirect to the Git local directory. Next, generate multiple files and view the current status for verifying the generated files by using the “git status” command. Execute the “git add –interactive” command to make amazing commits and track the files. This tutorial stated the method for making amazing commits by using the “git add –interactive” command.

Share Button

Source: linuxhint.com

Leave a Reply