Do you know how to view changes made to a file in GitHub?
Updated by Brook Jeynes [SSW] 2 months ago. See history
123
If you find a mistake in a file hosted on GitHub, don’t just fix it blindly - check who made the change and why. This helps you understand the context and gives you the chance to inform the contributor if a correction is needed. GitHub makes it easy to view a file's version history, compare changes, and even see discussions around each commit. ## Viewing changes to a file in GitHub 1. Navigate to the file in the repository on GitHub <imageEmbed alt="Image" size="large" showBorder={false} figureEmbed={{ preset: "default", figure: 'File within GitHub UI', shouldDisplay: true }} src="/uploads/rules/view-file-changes-in-github/github-file.png" /> 2. Click on the "History" button (clock icon) at the top right of the file view. You’ll see a list of commits that modified this file <imageEmbed alt="Image" size="large" showBorder={false} figureEmbed={{ preset: "default", figure: 'GitHub history button', shouldDisplay: true }} src="/uploads/rules/view-file-changes-in-github/github-history-button.png" /> 3. Click on a commit to view the **diff** - the [changes between two file versions](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/viewing-and-comparing-commits/differences-between-commit-views), showing what was added, deleted, or changed <imageEmbed alt="Image" size="large" showBorder={false} figureEmbed={{ preset: "default", figure: 'Select a commit from the list', shouldDisplay: true }} src="/uploads/rules/view-file-changes-in-github/github-commit-viewer.png" /> <imageEmbed alt="Image" size="large" showBorder={false} figureEmbed={{ preset: "default", figure: 'View the changes made', shouldDisplay: true }} src="/uploads/rules/view-file-changes-in-github/github-diff-view.png" /> <asideEmbed variant="info" body={<> If you're working locally, you can also run the following commands to view the exact changes within the terminal. ```shell git log -- path/to/file git show <commit-hash> ``` </>} figureEmbed={{ preset: "default", figure: 'XXX', shouldDisplay: false }} />