Skip to content

Instantly share code, notes, and snippets.

@anandarajm
Last active August 25, 2020 23:48
Show Gist options
  • Save anandarajm/ca2763d8e8048c6b9ddd4d8b7d969be1 to your computer and use it in GitHub Desktop.
Save anandarajm/ca2763d8e8048c6b9ddd4d8b7d969be1 to your computer and use it in GitHub Desktop.
Notes related to Git

Git Notes

Modifying/Undoing commits

To move the changes from one branch to another - Use cherry-pick

e.g. 'git checkout git cherry-pick '

Three types of git reset

git reset --soft

Keeps the modified files in staging directory and resets to specified hash

git reset (mixed - default)

Keeps the modified files in working directory and resets to specified hash

git reset --hard

Resets the files to its original state. If there are any untracked file or directory then use git clean -df

git revert

Very similar to git reset, however reverts the changes without messing up the history of the commit. This command will isntead create a new commit to undo the changes.

git stash save "message"

Git stash is very much like git commit, but the commit will be saves in a stash with ID To list the stash - git stash list To retrieve the stashed changes

  1. git stash apply stash@{0} - This keeps the changes stash changes in tact.
  2. git stash pop - This will pop out the changes from stash and stash will be empty To delete a stash entry - git stash drop stash@{0} To clear all stash entries - git stash clear

Git stash is branch independent

Virtual environments

'virtualenv -p /usr/bin/python3.7

source /bin/activate

deactivate'

To move the changes from one branch to another - Use cherry-pick

e.g. 'git checkout git cherry-pick '

Three types of git reset

git reset --soft

Keeps the modified files in staging directory and resets to specified hash

git reset (mixed - default)

Keeps the modified files in working directory and resets to specified hash

git reset --hard

Delete a branch

git checkout master git branch -d

Delete a branch remotely

git push --delete . For example: git push origin --delete fix/authentication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment