Skip to content
Source
Sign inSign up

Read a file and its history

Code and repositories / Read code

Read a file and its history

You open a CSV file and see a wall of commas, a PDF that you have to download first, or an SVG file full of path data. Or you want to see how a file looked three commits ago. The file page shows a table as a table, a diagram as a diagram, a PDF in your browser's PDF viewer and a picture as a picture. Its History panel steps through the commits of the file on the same page.

6 min read

1. See a file as it looks

Open a repository, then click a file in the file list.

  • A markdown, SVG, CSV, TSV or mermaid file has a Preview and Code switch above the file. Preview is on when the page opens.
    • In Preview, markdown shows as formatted text, and an SVG as an image on a checkered background. A CSV or TSV file shows as a table (see the next step). A mermaid file (.mmd or .mermaid) shows as a diagram.
    • In Code, you see the source and the number of lines.
  • A PDF file shows in the PDF viewer of your browser, with its pages, zoom and search. Download saves the file.
  • Other images (png, jpg, gif, webp, ico, bmp, avif) show as images.
  • Raw opens the bytes of the file. An SVG or an image opens as an image, and a PDF opens in the PDF viewer of your browser.

The header of the file shows the icon of the file, the same icon as in the file list.

The file page of an SVG file. Preview is on, and the logo shows as an image on a checkered background.

A mermaid file draws the same way as a mermaid block in Markdown (see Write comments and descriptions). When the file has an error, the page says that the diagram could not be drawn, and shows its source.

The file page of a mermaid file. Preview is on, and the flowchart of the file shows as a diagram.

A browser that cannot show a PDF in a page, such as Chrome on Android, says so in place of the PDF. Use Raw or Download there.

The file page of a PDF file. The PDF viewer of the browser shows its first page, with Raw and Download above it.

2. Read a CSV file as a table

A CSV file (.csv) or a TSV file (.tsv) opens as a table.

  • The first row of the file is the header of the table. Each row after it has its number on the left.
  • The table scrolls in its own box. The header stays at the top of the box, and the row numbers stay at its left edge, so you keep your place in a long or wide file.
  • A field in double quotes can hold commas, line breaks and quotes ("" is one quote), as in a file that a spreadsheet writes.
  • The table shows the first 5,000 rows, and at most 100,000 cells. When the file has more, Showing the first 5,000 rows. is above the table. A wide file shows fewer rows. A file over 1 MiB shows the rows of its first 1 MiB.
  • When the file is not a valid CSV file, for example when a quoted field does not end, the page says what is wrong and on which line, and shows the code of the file under that note.

To see the text of the file, click Code.

The file page of a CSV file. Preview is on, and the file shows as a table with a header row and a number on each row.

The Preview tab of a file in a diff (a pull request, a commit or a compare view) shows a CSV, TSV or mermaid file the same way. When the change keeps the file, Old and New switch between its two versions.

3. Open the history of the file

Above the file, a strip shows the last commit that changed the file, also when that commit is old. Click History in that strip.

When the git servers are busy, or their read of the history takes more than 30 seconds, the strip shows Open History to see the last commit in place of the commit. The page then says Could not load the last commit, with Retry. Click Retry, or click History. See Limits of big folders and long histories.

A panel with the title History opens on the right. It lists the commits that changed the file, newest first.

  • The list uses the branch (or the ref) that the page showed when you opened the panel.
  • It shows 35 commits. To see more, click Load more.

4. Step through the commits

  1. Click a commit in the panel. The page shows the file as it was at that commit.
  2. Click the next commit. The panel stays open and marks the commit that you look at.
  3. To go back to the newest version, click the first row, Latest on and the name of the branch.
The History panel on the right of a file page. A commit is marked in the panel, and the file next to it shows that commit.

Note

The history does not follow a rename. If you click a commit from before the file got its current path, the page says that the file is not found. At that commit, the file had a different path.

5. See the full history

Click Full history at the bottom of the panel. The commits page of the file opens.

On a folder page, History opens the commits page. It does not open a panel.

Done

You see a CSV or TSV file as a table, a mermaid file as a diagram, a PDF in your browser's viewer and an SVG or an image as a picture. Code shows the text of a file that has a Preview. You step through the commits of a file in the History panel, and you stay on the file page.

From the command line, src repo read-file <path> --ref <sha> prints the file at a commit (see Install and set up the CLI).

To change the file, click the pencil above it, or ... > Delete file. See Edit files in the browser.

When someone pushes while you read

Someone pushes to the branch while you read a file. The file does not change under you. A bar says New changes were pushed.

  1. Click Show them.
  2. The page loads the new version of the file. Your scroll position stays.

The file list and the commits load a push by themselves. See See changes without a reload.