.git
, where git keeps all of its metadata for the repository. The content of the .git
directory are private to git.
git commit --amend
”. When you run this command, you can fix the broken commit message in the editor.
Git | GitHub |
---|---|
Git is a software | GitHub is a service |
Provides a desktop interface called git GUI | Provides a desktop interface called GitHub Desktop. |
This is a distributed version control system installed on local machines which allow developers to keep track of commit histories and supports collaborative work. | This is a cloud-based source code repository developed by using git. |
This is maintained by “The Linux Foundation”. | This was acquired by “Microsoft” |
SVN, Mercurial, etc are the competitors | GitLab, Atlassian BitBucket, etc are the competitors. |
C
’ language. GIT is fast, and ‘C
’ language makes this possible by reducing the overhead of run times associated with high-level languages..git sub-directory
. Instead, it contains all the contents of the .git sub-directory
directly in the main directory itself, whereas the working directory consists of :Command | Meaning |
---|---|
git status | Gives a list of which files are staged, unstaged, and untracked |
git log | Illustrates the entire commit history by using the default format |
git diff | Displays the unstaged changes between index and working directory |
git revert <commit> |
Undoes all the changes made in <commit> and applies it to the current branch by creating a new commit |
git reset <file> |
Removes <file> from a staging area without overwriting any changes by keeping the working directory unchanged |
git config
” : Configure the username and email addressgit add
” : Add one or more files to the staging areagit commit
” : Commit changes to head but not to the remote repositorygit diff
” : helps in showing changes between commits and those between commits and working tree.git status
” : helps in showing differences between the index and working directoriesgit stash applies
” : is the command for bringing back saved changes on the working directorygit log
” : helps in finding a specific commit in the historygit init
” : Initialize an empty Git repositorygit checkout
” : is the command for updating directories of the working tree with directories from another branch without merginggit rm
” : helps in removing files from staging area and files on the diskgit reset
” : command helps in resetting the index. It also helps in resetting working directory to the state of the last commitgit is a tree
” : is ideal for the representation of a tree object alongside the mode and name for each itemSHA-1
value of the blob.
git add
. command.<file_name>
command.git add /<folder_name>/
command.Git | SVN |
---|---|
Decentralized and distributed version control tool | Centralized version control tool |
Clones all repositories on the local system | Stores version history on the server-side repository |
Supports offline commits | Supports online commits only |
Swift push/pull operations | Slow push/pull operations |
Automatically shares work to commit | Doesn’t support automatic sharing |
The contents of Git are hashed using the SHA-1 hash algorithm. | SVN doesn’t support hashed contents. |
git pull
” and “git fetch
” are used for downloading new data from a remote repository.git pull
" : This command is used to update the current HEAD data branch with all the changes that occurred in the remote repository. Thus, it downloads the data and integrates it with existing working files.git fetch
" : It downloads new data from the repository but does not support integrating this data into working files. It offers a fresh view of things that happened in the remote repository.git merge –abort
” command, and you will be able to undo the merge and start the task again.
git cherry-pick
” command. This command will allow you to apply commit from one branch to another branch. $ git cherry-pick <commit id>
Git cherry-pick
command can sometimes result in duplicate commits, and thus, it must be cautiously used. The below situations are apt if planning to use the git cherry-pick
command :git instaweb
” command helps in automatically directing a web browser and running a web server with an interface to the local repository.
command: git rebase -i HEAD~{{N}} where {{N}}
represents the number of commits needed to be squashed. <<installation_path>>/etc/gitconfig
file that has settings defined and applied to every user of the system and all their repos.--system
to git config command.~/.gitconfig
file or ~/.config/git/config
that has the scope specific to the user.--global
to the git config command.--local
to the git config command.This is the default config file that gets accessed and modified upon in case we do not specify any levels.git revert | git reset |
---|---|
This command is used for creating a new commit that undoes the changes of the previous commit. | This command is used for undoing the local changes done in the git repository |
Using this command adds a new history to the project without modifying the existing history | This command operates on the commit history, git index, and the working directory. |
Staging Area
’ or ‘Index
’. From the diagram it is evident that every change is first verified in the staging area I have termed it as “stage file” and then that change is committed to the repository. git reflog <ref_name>
”.stash drop
’ command is used to remove the stashed item. It will remove the last added stash item by default, and it can also remove a specific item if you include it as an argument.stash@{0}
: WIP on master: 049d078 added the index filestash@{1}
: WIP on master: c264051 Revert “added file_size
”stash@{2}
: WIP on master: 21d80a5 added number to logstash@{0}
use command git stash drop stash@{0}
.git branch --merged
helps to get the list of the branches that have been merged into the current branch.git branch --no-merged
lists the branches that have not been merged to the current branch.command: git commit -m "<message>"
<name of bad commit>
command: git checkout -b <<new_branch_name>>
. This ensures that a new branch is checkout out and not a commit/tag thereby ensuring that a detached state wouldn't happen.git reset filename
# orecho filename >> .gitingore
# add it to .gitignore to avoid re-adding it<paths>
is exactly the opposite of git add <paths>
.git bisect <subcommand> <options>