git rebase -i HEAD~3
// To pick three commits including HEAD. So, you get HEAD, HEAD^, HEAD^^
squash a commit ig you want to combine two commits as a single one.
git checkout <commit_hash> -- <file/folder name>
git diff <commit_hash> -- <file/folder name>
If you forgot to add any files to the previous commit, do git add
for them and then do amend
git commit --amend
To amend the author name and email,
First do :
git config user.name "User name"
git config user.email "[email protected]"
Then :
git commit --amend --reset-author
git remote update origin --prune
git stash save "some message here to remember stash by"
To save untracked files, git stash save -u ....
git stash list
- To see the available stashes.
git stash pop
- Applies the stash on the current commit and deletes from the stash (By deafult takes the first stash stash{0}
)
git stash apply
- Applies the stash on the current commit but keep the stash for alter use (By deafult takes the first stash stash{0}
)
git stash drop stash{<Num>}
- Deletes that stash completely
git stash show -p stash@{1}
- Shows the files in it as a diff
git config --global push.default tracking
- Pushes only the current branch and only if tracking is enabled.
By default Git pushes all branches that have changes compared to thier remote tracking branches. This makes it safer
git count-objects -v -H
Output contains:
count: the number of loose objects
size: disk space consumed by loose objects, in KiB (unless -H is specified)
in-pack: the number of in-pack objects
size-pack: disk space consumed by the packs, in KiB (unless -H is specified)
prune-packable: the number of loose objects that are also present in the packs. These objects could be pruned using git prune-packed.
garbage: the number of files in object database that are neither valid loose objects nor valid packs
size-garbage: disk space consumed by garbage files, in KiB (unless -H is specified)
git branch --contains <commit>
- Lists all branches that have the exact commit
git log -S 'search term' --source --all
--source : Shows which branch/stash/tag it picked the commit from
--all: Look in all branches