Skip to content

Commit

Permalink
Merge pull request #453 from FaizanCod/master
Browse files Browse the repository at this point in the history
Added undo and other commands in git
  • Loading branch information
onecompiler-ops authored Oct 18, 2022
2 parents 8f318b5 + 4fc501f commit b51d391
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion git.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---


Expand Down Expand Up @@ -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

```
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b51d391

Please sign in to comment.