You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
git checkout -b <newBranchName>
git branch --edit-description
git push origin <newBranchName>
Note: --edit-description is for editing the commit message for the branch creation
git rebase -i HEAD~n
where n is number of last commits which you want to rebase
Note: The above command will open a editor and will give various rebase options use reword option to select the commits whose commit message you want to change. After selecting the commits close the file. git will open all the commits one by one to allow rewording the commit message.
View changes in commit
git show <commit hash>
Note: You can get the commit hash from git log command
Undo last commit
git reset --soft HEAD~n
where n is number of last commits which you want to undo
Cherry Pick a commit from other branch
git checkout <branch to apply the commit>
git cherry-pick <commit hash>
Note: You can get the commit hash from git log command
git checkout --ours <filePath>
git checkout --theirs <filePath>
Note: if you want to merge both the changes then change the file and add the file to the commit using git add
git revert -m 1 <commitHash>
Note: 1 indicates that you want to go to first ancestor of this commit
Remove a big file from a specific commit pushed to remote
git rebase -i <commitHash - 1> # the commit hash of one commit before the commit which has the big file it will open editor, change *pick* to *edit* for the wrong commit which has the big file and close the editor
git rm --cached <Path to bigFile>
git commit --amend -C HEAD
git rebase --continue
git push --force
Stash
Stash local uncommitted changes
git stash
Note: all the files added to a commit will be un-staged and put in stash
List all stashes
git stash list
Apply stashed changes
git stash pop
Note: this will apply the stash and delete the stash changes
Apply stashed changes to multiple branches
git stash apply
git checkout <branchName>
git stash apply
git stash drop
Note: last step will delete the stash
View diff from stash without applying
git stash show -p stash@{n}
where n is the stash number you want to view, to get the stash number use git stash list command
Commit Logs
Show all commit logs
git log
Show all of your commits
git log --author='Your Name'
or
git log --author='[email protected]'
Show all unpushed commits
git log --branches --not --remotes
Note: the above command will list all the unpushed commits in all branches
Show all commits which are present in one branch and not in other