git commands
git commands
git hash-object newfile.txt -w (This will create a blob by taking the input from a
file)
find .git/objects -type f (This will list all the objects in the .git/objects
directory)
# now to create a tree, first create a file with the following content
100644 blob 83baae61804e65cc73a7201a7252750c76066a30 newfile.txt
git ls-files (This will list all the files which are in the staging area)
git ls-files -s (This will list all the files which are in the staging area along
with their SHA-1 hash,file permissions,file names and number of times they are
modified)
git read-tree (This will read the tree object and will create a staging area,It
will copy all the files from the tree object to the staging area)
git checkout-index -a (This will copy all the files from staging area to working
directory)
git config --list (This will list all the configuration settings,like user email,
username etc)
git config --global user.name "Your Name" (This will set the username globally)
git config --global user.email "Your Email" (This will set the user email globally)
git add filename (This will add the file to the staging area)
git add . (This will add all the files to the staging area)
git rm --cached filename (This will remove the file from the staging area)
git commit -m "Commit Message" (This will commit the changes to the local
repository)
git commit (This will open the default editor to write the commit message, after
writing the commit message save and close the editor to commit the changes to the
local repository)
git log (This will list all the commits in the local repository)
git log --oneline (This will list all the commits in the local repository in one
line)
git log --oneline --graph (This will list all the commits in the local repository
in one line along with the graph)
echo -e "blob//|OHello, Git" | sha1sum (This will give us the SHA-1 hash code of
the this written string)
git branch (This will list all the branches in the local repository)
git branch branchname (This will create a new branch in the local repository)
git checkout -b branchname (This will create a new branch and switch to that
branch)
git branch -d branchname (This will delete the branchname branch, but it will not
delete the commits which are in the branchname branch)
git branch -D branchname (This will delete the branchname branch, and it will also
delete the commits which are in the branchname branch)
git checkout -m branchname (This will merge the branchname branch to the current
branch)
git branch -m oldname newname (This will rename the oldname branch to newname
branch)
dipp
cat .git/refs/heads/master (This will print the SHA-1 hash code of the master
branch)
fast forward merge can be performed when there is direct path from source branch to
the target branch
git merge -s recursive branch1 branch2 (This will merge the branch1 branch to the
branch2 branch)
git merge -s resolve branch1 branch2 (This will merge the branch1 branch to the
branch2 branch)
git merge -s octopus branch1 branch2 branch3 branchN (This will merge the branch1
branch2 branch3 branchN branches to the master branch)
git merge -s ours branch1 branch2 branchN (This will merge the branch1 branch2
branchN branches to the current branch)
git merge -s subtree branchA branchB (This will merge the branchA branchB branches
to the current branch)
git stash (This will stash the changes in the working directory which are staged or
commited but remember we need initial commit to perform this operation)
git stash -a (This will stash the changes in the working directory which are not
staged and ignored)
git stash pop (This will apply the last stash and remove it from the stash list)
git stash --patch or git stash -p (This will check the difference between the
commit and last stash)
git stash save "description" (This will stash the changes in the working directory
with a description)
git stash apply stash@{stash number} (This will apply the stash with the given
stash number)
git stash drop stash_id (This will drop the stash with the given stash_id)
git stash show stash_id (This will show the stash with the given stash_id)
git stash show -p stash_id (This will show the stash with the given stash_id along
with the difference)
git stash branch branchname stash_id (This will create a new branch with the given
branchname and apply the stash with the given stash_id to the new branch)
git stash branch branchname stash@{stash_id} (This will create a new branch with
the given branchname and apply the stash with the given stash_id to the new branch)
git tag -l "tagname*" (This will list all the tags which starts with v1.8.5)
git tag -a tagname -m "tag message" (This will create a tag with the given name and
message)
git tag -a tagname -m "tag message" commit_id (This will create a tag with the
given name and message and it will point to the given commit_id)
git tag -a tagname -m "tag message" -f commit_id (This will create a tag with the
given name and message and it will point to the given commit_id and it will
overwrite the existing tag)
git tag -d tagname (This will delete the tag with the given name)
git tag -d tagname1 tagname2 tagnameN (This will delete the tag with the given
name)
git tag -d $(git tag -l "tagname*") (This will delete all the tags which starts
with tagname)