# Shows the commits that touched file.txt git log -stat file.txt Viewing the history of a file git log file.txt # Terminates the bisect session Finding contributors git shortlog # Marks the given commit as a good commit git bisect reset # Marks the current commit as a bad commit git bisect good ca49180 # Checks out the master branch Finding a bad commit git bisect start git bisect bad # Checks out the given commit git checkout master # Changes to file.txt only Checking out a commit git checkout dad47ed # Shows the changes between two commits git diff HEAD~2 HEAD file.txt # Shows the version of file stored in this commit # Commits that touched file.txt Formatting the log output git log -pretty=format:”%an committed %H” Creating an alias git config -global alias.lg “log -oneline" Viewing a commit git show HEAD~2 git show HEAD~2:file1.txt # Commits with “GUI” in their patches git log hash1.hash2 # Commits with “GUI” in their message git log -S“GUI” # Shows the last 3 entries git log -author=“Mosh” git log -before=“” git log -after=“one week ago” git log -grep=“GUI” # Shows the actual changes (patches) Filtering the history git log -3 # Shows the list of modified files git log -patch Restoring an earlier version of a file git restore -source=HEAD~2 file.jsīrowsing History Viewing the history git log -stat # Discards all local changes (except untracked files) git clean -fd # Restores multiple files in working directory git restore. # Copies file.js from index to working directory # Copies the last version of file.js from repo to indexĭiscarding local changes git restore file.js # Shows the version of file.js stored in the last commit Unstaging files (undoing git add) git restore -staged file.js # Two steps before the last commit git show HEAD:file.js # Lists the commits from the oldest to the newest Viewing a commit git show 921a2ff # Same as the above Viewing the history git log # Shows unstaged changes git diff -staged # Removes from staging area only Renaming or moving files git mv file1.js file1.txt Viewing the staged/unstaged changes git diff # Removes from working directory and staging area git rm -cached file1.js # Opens the default editor to type a long message Skipping the staging area git commit -am “Message” Removing files git rm file1.js # Commits with a one-line message git commit # Short status Committing the staged files git commit -m “Message” # Stages the current directory and all its content Viewing the status git status # Stages a single file git add file1.js file2.js ✓ Rewriting history Creating Snapshots Initializing a repository git init Staging files git add file1.js This cheat sheet covers all of the Git commands I’ve covered in my Ultimate Git The essential Git commands every developer must know The essential Git commands every developer must know.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |