🚨 Time is Running Out: Reserve Your Spot in the Lucky Draw & Claim Rewards! START NOW

Code has been added to clipboard!

How to Untrack Files and Examine Repository

Reading time 5 min
Published Jan 31, 2018
Updated Oct 3, 2019

After working with Git for a while, cloning a repository or making a couple of commits, you will soon want to Git untrack file or to check the status of the processes that have been made in your repository. There might be a number of reasons why you want to Git untrack file. Not all the files need to be tracked - some of them can be easily created again, or they occupy the workflow. In most cases, files falling to Git untrack file category include various machine generated files.

Another thing that might be important to you is how to check Git commit command history - of your own or other users. In the previous tutorials, you have learned to use one command to check the information at the working directory: git status. However, this command, even though it shows all the untracked, unstaged and staged files, it does not include the information about the committed project history. There exist another powerful function which enables you to perform a careful investigation on your repository: git log. It can perform several actions that help you examine your repository, for example, to search the repository according to Git commit message.

All the information about how to Git untrack file and check the status of a repository is below, so start reading now!

Git Untrack File: Main Tips

  • You can use .gitignore to untrack files.
  • To check Git add, Git add all and Git commit history in a repository you can use git log command.
  • By adding an option to command, you can narrow down or widen the range of an operation.

Untracking and Ignoring Files

There might be cases when you don't want to start tracking some files. Then you can add all of them to .gitignorefile and basically execute Git untrack file. First of all, you should create a file .ignore. Secondly, open it in a text editor and list all the files on a separate line. '#' is used for comments and '*' to describe the type of the files. For example:


# Files to ignore
*.dex
*.class
bin/
gen/

Note that if you are on Windows, you will not be allowed to create an empty file with .gitignore. Fortunately, Git has a tool that you can use to create such a file. You should type this into a terminal:

$ touch .gitignore

This command will create the file .gitignore. If you run status, you will see that there is an untracked file:

Untracked files:
(use "git add <file>..." to include in what will be committed)

.gitignore

The next step is to add and commit the .ignore file. After executing add command, you will see git ignore as a new file and after commit it will disappear. If you rerun Git status, you will not be able to see that file anymore.

To see all the files that reside in a repository, run ls -a. This command will show all the tracked and untracked files. This command should show your .gitignore file:

$ls -a
./ ../ .got/ /gitignore firstfile.txt

DataCamp
Pros
  • Easy to use with a learn-by-doing approach
  • Offers quality content
  • Gamified in-browser coding experience
  • The price matches the quality
  • Suitable for learners ranging from beginner to advanced
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid Certificates of completion
Udemy
Pros
  • Easy to navigate
  • No technical issues
  • Seems to care about its users
Main Features
  • Huge variety of courses
  • 30-day refund policy
  • Free certificates of completion

Investigating Repository History

The other command that you can use is a more elaborated tool to view the history of Git commit command and inspect the working directory with the staging area. You can try to inspect the history of the project by typing this line:

$ git log

It will display the entire Git commit history. If no arguments are added, git log by default will list all of the commits with its ID - SHA - 1 checksum from the latest to the oldest. Information about the commit's author's name and email, date, and a message will be displayed.

There is a vast variety of options available with Git log command. If you want not only to see the history of commits but also to create changes in the files, you should use this command: git log --stat.

Check the example below:

commit e8353493b09b6ffa095cc10568a7fca5ab6428ce

Author: Your Name &lt;[email protected]&gt;

Date: Mon Jan 22 15:18:42 2018 +0200

edited the version

.gitignore | 2 ++

first_file.text | 3 ++-

2 files changed , 4 insertions(+), 1 deletion(-)

As you can see, this option shows the commits and changes to the files - how many files were changed and the number of added or deleted lines in them.

Another helpful option is -p/--patch, which provides the most detailed view of the project history. The command for this is - git log -p or git log --patch. Not only will it show the number of the changed lines but also the changes themselves.

If you have to look at many commits, you can see a more compact report by adding an option git log --oneline:

$git log --oneline

9f6f817 (HEAD -> master) Committed few things for example

0519da5 A small way around the staging area

As you can see, this will print all the commits in one line.

Similarly, you can use the option to narrow down and limit what log information to print on your screen. You can reduce the number of commits shown with git log -n <limit>. You can search for commits in a particular time interval with git log <since>...<until>.

If you work with other people, it might be useful for you to check the Git log of a single user commits sometimes. You can find all the commits done by a certain author by typing git log --author="author_name". You can also list all the commits of a specific file by using <file> option or find a certain file by a Git commit message.

Git Untrack File: Summary

  • .gitignore is the command used to Git untrack file.
  • git log command is used when you want to check Git add, Git add all and Git commit history made by you or other user.
  • It is possible to widen an operation by adding an option to the command.