Time for action – usage of .gitignore

  1. Open your text editor and type the following:
    ~*.*
  2. Save the file as .gitignore inside our Workbench repository, as shown in the following screenshot:
    Time for action – usage of .gitignore

    Make sure to select the All Files option from the Save as type listbox when you save the file.

What just happened?

We have successfully commanded Git to ignore the temporary file created by the Word application. Go ahead and refresh your GUI or get the status from your CLI now. The only addition to your content.docx file in the Unstaged Changes area would be the .gitignore file and not the temporary file.

Every time Git wants to check for new files (untracked changes) present in the repository it checks with the .gitignore file for exclusions. By observing the temporary file's name (~$ontent.docx) we can guess that any temporary file created by Word is going to start with the special character ~ so we put an entry in .gitignore to match all files starting with that character. The very entry ~*.* under the .gitignore file says to exclude any filename starting with the character ~ with any extension.

Note

Though addition of the .gitignore file itself is a one-time process, the exclusion rules inside the file have to be updated as per the nature and content type of the files added in the repository as required.

Undo addition

At any given point of time before committing, if you want to move a file from the Staged Changes to the Unstaged Changes area you can do the following:

  • GUI: Click on the tick icon next to that particular filename present in the Staged Changes pane
  • CLI: Use the following command:
    git reset filename.extension
    
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.125.219