User Tools

Site Tools


cheatsheet:git

This is an old revision of the document!


git command cheatsheet

unstage files (if you have "git add" the wrong file)

git restore --staged some.file

revert 1 or more local commits (not yet pushed)

$ git reset --soft HEAD~1
 
Unstaged changes after reset:
D	somefolder/somefile
M	somefolder/someother.file

revert to a previous commit (already pushed)

git reset --hard <commit>

git reset details

git reset [<options>] [<commit>]

  • [<commit>] is the commit identifier (hash or reference) to reset to.
  • [<options>] are optional flags that modify the behavior of the reset command.

Some possible options:

--hard: Reset the repository to the specified commit and discard all changes in the working tree.

--soft: Reset the repository to the specified commit, but keep changes in the working tree.

--mixed (default): Reset the repository to the specified commit, but keep changes in the index (staging area).

--merge: Reset the repository to the specified commit and keep changes that have been made in the working tree.

--keep: Keep changes in both the working tree and the index (staging area).

other common commands

git init: Initialize a new Git repository.

git clone <repository_url>: Clone an existing Git repository.

git add <file_or_directory>: Stage changes to a file or directory for the next commit.

git reset <file_or_directory>: Unstage changes to a file or directory.

git commit -m “<message>”: Commit staged changes with a message.

git log: Display the commit history of the repository.

git status: Display the current status of the repository, including staged and unstaged changes.

git diff: Display the difference between the current state and the last commit.

git checkout <branch_or_commit>: Check out a different branch or commit.

git branch: Display a list of local branches.

git branch <branch_name>: Create a new branch.

git checkout -b <branch_name>: Create and checkout a new branch.

git merge <branch_name>: Merge changes from another branch into the current branch.

git rebase <branch_name>: Rebase the current branch on top of another branch.

git fetch: Download new changes from the remote repository.

git pull: Fetch and merge changes from the remote repository.

git push: Upload local changes to the remote repository.

git stash: Save changes that have not yet been committed to a temporary stash.

git stash apply: Apply changes from a stash to the working tree.

git stash drop: Remove a stash from the stash list.

cheatsheet/git.1676371719.txt.gz · Last modified: 2023/02/14 10:48 by kamaradski