Back

How to Identify Modified Files After a Git Commit

How to Identify Modified Files After a Git Commit

When working with Git, you might find yourself in a situation where you’ve made a commit but can’t remember which files were modified. Fortunately, Git provides multiple ways to track down these files. In this guide, we’ll go through different methods to check which files were modified after a commit, both locally and remotely.

Key Takeaways

  • Use git show --name-only to see modified files in the last commit.
  • Use git log -1 --stat for a summary of modified files and changes.
  • Use git diff and git reflog to track modifications across different commits.
  • Check changes remotely using GitHub’s web interface or CLI.

Checking Modified Files Locally

1. View Files Modified in the Last Commit

If you want to see a list of files that were modified in your most recent commit, use:

git show --name-only

This will display the commit message followed by the list of modified files.

Alternatively:

git log -1 --stat

This provides a summary of changes, showing modified files and the number of lines added or removed.

2. Check File Differences Between Commits

Compare the last commit with the one before it:

git diff HEAD~1 HEAD --name-only

To check modifications between two specific commits:

git diff <commit-hash-1> <commit-hash-2> --name-only

3. Check History of a Specific File

If you’re looking for modifications to a specific file:

git log --oneline -- filename

For a more detailed view:

git log -p -- filename

4. Check Uncommitted Changes

If you suspect you still have uncommitted modifications, check:

git status

To see exact changes:

git diff

To check staged but uncommitted changes:

git diff --cached

5. Check If You Committed to a Different Branch

To check your current branch:

git branch

To list recent commits across branches:

git reflog

Checking Modified Files in a Remote Repository (GitHub)

Using GitHub Web Interface:

  1. Navigate to your repository on GitHub.
  2. Click on Commits in the repository.
  3. Click on the commit you want to inspect.
  4. You will see a list of modified files along with the changes in the commit.

Using GitHub CLI:

To fetch commit details using the GitHub CLI:

gh repo view <repository-name> --web

To check a remote repository from the command line:

git fetch origin

Then, compare the latest remote commit with your local commit:

git diff origin/main HEAD --name-only

This will show file differences between your local branch and the remote repository.

Conclusion

Git provides powerful tools to track file modifications even after a commit. Whether you’re looking for changes in your last commit, comparing between versions, or checking modified files remotely on GitHub, these commands will help you stay in control of your codebase. Next time you’re unsure about what was modified, just run git show --name-only to quickly find your changes!

FAQs

Use `git show --name-only` or `git log -1 --stat`.

Run `git diff <commit-hash-1> <commit-hash-2> --name-only`.

Use GitHub’s web interface or GitHub CLI with `gh repo view <repository-name> --web`.

Listen to your bugs 🧘, with OpenReplay

See how users use your app and resolve issues fast.
Loved by thousands of developers