From 4fc501f2c3bad475abbc41dd4c12ee8833a41f8f Mon Sep 17 00:00:00 2001 From: Faizan Choudhary Date: Tue, 18 Oct 2022 23:49:03 +0530 Subject: [PATCH] added undo and other commands --- git.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/git.md b/git.md index c4e51e7..8b7e268 100644 --- a/git.md +++ b/git.md @@ -2,7 +2,7 @@ title: Git description: Git is a version-control system for tracking changes in computer files and coordinating work on those files among multiple people created: 2018-07-18 -updated: 2022-10-01 +updated: 2022-10-18 --- @@ -39,6 +39,7 @@ git checkout [branch-name] # switch to given branch git merge [branch] # merge the specified branch’s history into the current one git log # Shows current branch's commit history git log -p # Display the full diff of each commit +git log -p [fileName] # Shows changes over time for a specific file git log --stat # Include which files were altered and the relative number of lines altered ``` @@ -47,7 +48,9 @@ git log --stat # Include which files were altered and the relative ```sh git add . # Add all files +git add -p [fileName] # Add some changes in file to the next commit git commit -m "commit message" # commit +git commit --amend # Changes the last commit (Doesn't alter published commits) git status # Shows the modified files in working directory which are staged for next commit git reset [fileName] # Unstages file while retaining changes in present working directory git stash # to keep uncommitted changes (both staged and unstaged) for later use @@ -62,6 +65,7 @@ git diff --staged # Shows diff of what is staged but not commi git diff branch2...branch1 # Shows diff of what is in branch1 that is not in branch2 git diff HEAD # Shows difference between working directory and last commit git diff --cached # Shows difference between staged changes and last commit +git blame [fileName] # Shows who changed what and when in a file ``` ## Update @@ -76,6 +80,16 @@ git push [remote] --force # to forcefully upload your local repository git pull # to update the local version of a repository from a remote ``` +## Undo + +```sh +git revert [commit] # Revert to a previous commit (by producing a new commit with contrary changes) +git reset --hard HEAD # Discards all local changes in your working directory (DANGEROUS!) +git reset --hard [commit] # Resets your HEAD pointer to a previous commit and discards all changes since then (DANGEROUS!) +git reset --keep [commit] # Resets your HEAD pointer to a previous commit and preserves all changes as unstaged changes +git checkout HEAD [fileName] # Discard local changes in a specific file +``` + ## Stash ```sh