Skip to main content

Useful GIT commands

Useful GIT commands

To check all changes to files since, for example, Monday, you can do this:

git log

followed by

git diff --name-status b2c8b3d88dfd5439165f37f41d789f2239b34a6b

 

Before doing a GIT PULL, to check which files will be changed, type this: (Note: This ignores local modifications unless they won't be automatically merged, which is good for stuff like .htaccess)

git fetch && git diff HEAD @{u} --name-status

 

If you want to see ALL changes including uncommited local modifications, do this instead (This is more useful for a planned GIT RESET than a GIT PULL): 

git fetch && git diff @{u} --name-status

 

To see all changes to a single file, simply do this:

git log path/to/file

If you want to revert a single file to a previous version, do this: (Note: Running this will cause you to have uncommited local modifications, which will cause a merge conflict the next time you GIT PULL. Before GIT PULLING, you'll need to restore this file to the latest version.)

git checkout commitID path/to/file

 

If you're in middle of a merge conflict, and want to discard your local changes to a single file, you can use this:

git checkout --theirs path/to/file

If you want to modify your previous commit instead of creating a new commit, you can use this:
Note: You should not do this after you have already GIT PUSHED! If you try this, then it will cause MAJOR problems!

git add path/to/file
git commit --amend