Git Clean
Git Clean
---------- GIT_COMMANDS.TXT
git log -5
git log --follow a.txt
git log --stat
git log testingbranch
git log branchB..branchA ; shows the commits on Branch B not in Branch A
git log
git log -p -2 ; show patch diff
git log --pretty=format:"%h %s" --graph
git log --pretty=oneline --graph
git log --stat
git log --graph
git log -p ; shows the patch introduced in each commit.
git log --since=2.weeks; after 2 weeks
git log --after=2.weeks;after 2 weeks
git log --before=2.weeks;before 2 weeks
git log --until=2.weeks; commits made prior to 2 weeks.
git log -- path/to/file ;
git log --since="2008-10-01" --before="2008-11-01" ; list changes made in oct 2008.
git log --grep="string" ; commit messages which contains the string.
git log --author="magesh"
git log --all
git log --oneline --decorate --all --graph
---------- GIT_COMMANDS.TXT
git status -s or git status --short
git status
---------- GIT_COMMANDS.TXT
git diff ( diff of changed in working vs staged)
git diff --staged ( diff of what is staged to the last commit)
git diff --check ; to identify whitespace errors in commit files.
git diff BranchB...BranchA ; diff of Branch B vs Branch A
git diff <commit1> <comit2>
git diff HEAD ; diff between working directory and last commit.
---------- GIT_COMMANDS.TXT
git add -h ; concise help list
git add -A ( all files in working directory including the top level)
git add <file>
git add <directory)
git add .
git add -u mydir/ ; only modified and delted files will be staged.
git add --no-removal mydir/ ; only modified and new files staged.
---------- GIT_COMMANDS.TXT
git push ORIGIN ( push current branch)
git push ORIGIN --all ( push all branch)
git push ORIGIN <branch> ( push branch to remote)
git push -u ORIGIN <branch> ; create an upstream connection and push local branch
to remote.
git push ORIGIN --delete <branch> ; remote branch deletion
git push -u origin featureB:featureBee ; feature B local to featurebb remote.
git push origin <tagname>. ; by default git push will not push tags to remote.
git push origin v1.5 ; explicitly push tag to remote.
git push origin --tags ; push all tags to remote at once.
git push <remote> --follow-tags ; only annotated tags will be pushed to the remote.
git push origin HEAD:sfonet_f1 ; Current branch HEAD moved to sfonet_f1 remote
branch.
---------- GIT_COMMANDS.TXT
git pull ORIGIN ( fetch the remote copy of the current branch and merge it to
local)
git pull ORIGIN <branch>
git pull origin main --allow-unrelated-histories
git pull --rebase ORIGIN
---------- GIT_COMMANDS.TXT
git fetch alias ( fecth all branches from that remote repo)
git fetch origin
---------- GIT_COMMANDS.TXT
git add -A
git commit -m "added"
git commit -m "feature1"
git commit --amend -m "New Message" ; replaces the old Message with New for the
Last commit
git commit --amend ; interactive editor. we can add new files to an existing
commit.
git commit -a -m "mesg" ; to bypass staging area.
--------------------------------------------------------------------
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty Git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
---------- GIT_COMMANDS.TXT
git remote -v ; information about remote repository.
git remote show origin
git remote rename pb paul; rename remote connection.
git remote ; list the remte connetion.
git remote remove paul
git remote add alias URL ( setting up alias for remote repo)
git remote rm origin ; to remove the connections of the remote rep.
git remote ; to list the connections of the remote rep.
git remote show <remote> for remote branches as well as more information
---------- GIT_COMMANDS.TXT
git merge <branch> ( merge the Branch to the current branch)
git merge alias/branch ( merge remote branch to current branch)
git merge --squash feature ; will squash all changes in feature branch and merge to
Master. But not commit.
---------- GIT_COMMANDS.TXT
git rebase <branch> ; change the base of the current branch to that of <branch>
git rebase <base> base can be commit ID, branch name.
git rebase master ; change the base of the feature branch.
git rebase feature ; will make feature and master branch identical and HEAD for
both brach will be same
git rebase --onto master server client
git rebase <basebranch> <topicbranch> — which checks out the topic branch (in this
case, server) for you and replays it onto
git rebase basebranch
git rebase --onto master server client ; client will be rebased to Master
$ git rebase master server ( server branch will be rebased)
---------- GIT_COMMANDS.TXT
git stash save "working on Add function" ; revert to last commit.
git stash list ; list of all stashes.
git stash apply stash@[0] ; it will apply the stash but will not commit
git stash apply 2 ; will apply the stash 2. will work only when we prev stash is
not opened.
git stash applu --index
git stash push -m "Added Feature"
git stash drop 2 ; drop the stash index 2 in the stash.
git stash clear ; to clear all the stash entry.
git stash list
git stash -s (
git stash -u ( for stashing untracked file changes).
git stash -a ( all files including ignored files)
git stash --keep-index ; changes staged are not stashed.
git stash branch testbranch ; changes applied on testbranch and stash entry is
dropped.
git stash drop stash@[0]
git stash clear ; to clear all savepoint
git stash
git stash list
git stash pop
git stash drop
git stash apply
---------- GIT_COMMANDS.TXT
git clone https://[email protected]/rmagesh9999/sbo.git .
git clone <URL> <path of Dir>
git clone -o booyah ;then you will have booyah/master(instead of Origin) as your
default remote branch
---------- GIT_COMMANDS.TXT
git branch -r ; list the remote branches.
git branch -a ; list all local and remote branches.
git branch --merged ; list all the branches which are merged.
git branch --merged master ; list all branches merged to master.
git branch -d <branch> ; local branch deletion
git branch ( list)
git branch <New branch>
git branch -v ; to list all commit on each branch.
git branch --no-merged ; list non merged branches.
git branch -D testing; to forceful removal of branch whiah is not yet merged.
git branch --no-merged master ; to find out branches which are not yet merged with
master.
git branch --move bad-branch-name corrected-branch-name ; to rename a branch.
git branch -c Branch1 branch2 ; copy a branch1 to Branch2 with all the logs.
git branch -u origin/serverfix ;Branch serverfix set up to track remote branch
serverfix from origin.
git branch --unset origin/serverfix
git branch -vv ; to view all Tracking Branches.
git branch --all
---------- GIT_COMMANDS.TXT
git checkout feature/feature1
git checkout -b <new branch>
git checkout <branchname>
git checkout <Hashid> ; Hashid to be recovered. We are in a Detatched Head state.
git checkout -- ; checkout to last commit.
git checkout -- <file>... to discard changes in working directory; replace with
last committed.
git checkout -b serverfix origin/serverfix ; create a local based on remote branch
git checkout --track origin/serverfix ; will create a tracking branch in local
serverfix.
git checkout -b serverfix origin/serverfix
---------- GIT_COMMANDS.TXT
git reset <file>
git reset --hard <lastcommit> ; changes removed from working.
git reset --soft <lastcommit> ; changes preseved in staging.
git reset <lastcommit> ; changes moved from staging to working.
git reset HEAD <file>... to unstage
git checkout -- <file> ;to discard changes in working directory; replace with last
committed.
git clean -df ; remove all untracked files and directory.