IQ GIT
39) What is git Is-tree?
'git Is-tree' represents a tree object including the mode and the name of each item and the SHA-1 value of the blob or the tree.
What is 'git add' is used for?
'git add' adds file changes in your existing directory to your index.
What is the function of 'git diff ' in git?
'git diff ' shows the changes between commits, commit and working tree etc.
What is the difference between the 'git diff 'and 'git status'?
'git diff' is similar to 'git status', but it shows the differences between various commits and also between the working directory and index.
26) What is the difference between 'git remote' and 'git clone'?
'git remote add' just creates an entry in your git config that specifies a name for a particular URL. While, 'git clone' creates a new git repository by copying and existing one located at the URI.
What is "Staging Area" or "Index" in GIT?
Before completing the commits, it can be formatted and reviewed in an intermediate area known as 'Staging Area' or 'Index'.
Blobs?
Blob stands for Binary Large Object. Each version of a file is represented by blob. A blob holds the file data but doesn't contain any metadata about the file. It is a binary file, and in Git database, it is named as SHA1 hash of that file. In Git, files are not addressed by names. Everything is content-addressed.
Branches?
Branches are used to create another line of development. By default, Git has a master branch, which is same as trunk in Subversion. Usually, a branch is created to work on a new feature. Once the feature is completed, it is merged back with the master branch and we delete the branch. Every branch is referenced by HEAD, which points to the latest commit in the branch. Whenever you make a commit, HEAD is updated with the latest commit.
Commits?
Commit holds the current state of the repository. A commit is also named by SHA1 hash. You can consider a commit object as a node of the linked list. Every commit object has a pointer to the parent commit object. From a given commit, you can traverse back by looking at the parent pointer to view the history of the commit. If a commit has multiple parent commits, then that particular commit has been created by merging two branches.
42) Explain what is commit message?
Commit message is a feature of git which appears when you commit a change. Git provides you a text editor where you can enter the modifications made in commits.
Distributed Version Control System?
DVCS clients not only check out the latest snapshot of the directory but they also fully mirror the repository. If the server goes down, then the repository from any client can be copied back to the server to restore it. Every checkout is a full backup of the repository. Git does not rely on the central server and that is why you can perform many operations when you are offline. You can commit changes, create branches, view logs, and perform other operations when you are offline. You require network connection only to publish your changes and take the latest changes.
Git reset soft?
Each branch has a HEAD pointer, which points to the latest commit. If we use Git reset command with --soft option followed by commit ID, then it will reset the HEAD pointer only without destroying anything. git reset --soft HEAD~
Local Repository?
Every VCS tool provides a private workplace as a working copy. Developers make changes in their private workplace and after commit, these changes become a part of the repository. Git takes it one step further by providing them a private copy of the whole repository. Users can perform many operations with this repository such as add file, remove file, rename file, move file, commit changes, and many more.
Why GIT better than Subversion?
GIT is an open source version control system; it will allow you to run 'versions' of a project, which show the changes that were made to the code overtime also it allows you keep the backtrack if necessary and undo those changes. Multiple developers can checkout, and upload changes and each change can then be attributed to a specific developer.
What language is used in GIT?
GIT is fast, and 'C' language makes this possible by reducing the overhead of runtimes associated with higher languages.
head?
HEAD is a pointer, which always points to the latest commit in the branch. Whenever you make a commit, HEAD is updated with the latest commit. The heads of the branches are stored in .git/refs/heads/ directory.
Git reset hard?
If you use --hard option with the Git reset command, it will clear the staging area; it will reset the HEAD pointer to the latest commit of the specific commit ID and delete the local file changes too.
Remove changes from staging area?
If you want to undo a change from the staged area, then you can use the git checkout command, but with the checkout command, you have to provide an additional parameter, i.e., the HEAD pointer. The additional commit pointer parameter instructs the git checkout command to reset the working tree and also to remove the staged changes. [tom@CentOS src]$ git checkout HEAD -- string_operations.c
How can you create a repository in Git?
In Git, to create a repository, create a directory for the project if it does not exist, and then run command "git init". By running this command .git directory will be created in the project directory, the directory does not need to be empty.
23) To delete a branch what is the command that is used?
Once your development branch is merged into the main branch, you don't need development branch. To delete a branch use, the command "git branch -d [head]".
Git patch?
Patch is a text file, whose contents are similar to Git diff, but along with code, it also has metadata about commits; e.g., commit ID, date, commit message, etc. We can create a patch from commits and other people can apply them to their repository. git add string_operations.c git commit -m "Added my_strcat function" git format-patch -1 The above command creates .patch files inside the current working directory. you can use this patch to modify the files. Git provides two commands to apply patches git amand git apply, respectively. Git apply modifies the local files without creating commit, while git am modifies the file and creates commit as well.
pull?
Pull operation copies the changes from a remote repository instance to a local one. The pull operation is used for synchronization between two repository instances. This is same as the update operation in Subversion.
push?
Push operation copies changes from a local repository instance to a remote one. This is used to store the changes permanently into the Git repository. This is same as the commit operation in Subversion.
revision?
Revision represents the version of the source code. Revisions in Git are represented by commits. These commits are identified by SHA1 secure hashes.
Git show?
Shows one or more objects (blobs, trees, tags and commits). For commits it shows the log message and textual diff. It also presents the merge commit in a special format as produced by git diff-tree --cc. For tags, it shows the tag message and the referenced objects. For trees, it shows the names (equivalent to git ls-tree with --name-only). For plain blobs, it shows the plain contents. The command takes options applicable to the git diff-tree command to control how the changes the commit introduces are shown. This manual page describes only the most frequently used options.
Tags?
Tag assigns a meaningful name with a specific version in the repository. Tags are very similar to branches, but the difference is that tags are immutable. It means, tag is a branch, which nobody intends to modify. Once a tag is created for a particular commit, even if you create a new commit, it will not be updated. Usually, developers create tags for product releases. Show - git tag -l Create - git tag -a v1.4 -m "my version 1.4" Delete - git tag -d version1.4
What is the function of 'git config'?
The 'git config' command is a convenient way to set configuration options for your Git installation. Behaviour of a repository, user info, preferences etc. can be defined through this command.
Rebase Branches?
The Git rebase command is a branch merge command, but the difference is that it modifies the order of commits. The Git merge command tries to put the commits from other branches on top of the HEAD of the current local branch. For example, your local branch has commits A−>B−>C−>D and the merge branch has commits A−>B−>X−>Y, then git merge will convert the current local branch to something like A−>B−>C−>D−>X−>Y The Git rebase command tries to find out the common ancestor between the current local branch and the merge branch. It then pushes the commits to the local branch by modifying the order of commits in the current local branch. For example, if your local branch has commits A−>B−>C−>D and the merge branch has commits A−>B−>X−>Y, then Git rebase will convert the current local branch to something like A−>B−>X−>Y−>C−>D. multiple developers work on a single remote repository, you cannot modify the order of the commits in the remote repository. In this situation, you can use rebase operation to put your local commits on top of the remote repository commits and you can push these changes.
38) What is the function of 'git reset'?
The function of 'Git Reset' is to reset your index as well as the working directory to the state of your last commit.
What is the function of git clone?
The git clone command creates a copy of an existing Git repository. To get the copy of a central repository, 'cloning' is the most common way used by programmers.
What is the purpose of branching in GIT?
The purpose of branching in GIT is that you can create your own branch and jump between those branches. It will allow you to go to your previous work keeping your recent work intact. -- create a new branch using the git branch <branch name> command. We can create a new branch from an existing one. We can use a specific commit or tag as the starting point. If any specific commit ID is not provided, then the branch will be created with HEAD as its starting point.
25) What is the syntax for "Rebasing" in Git?
The syntax used for rebase is "git rebase [new-commit] "
45) What is 'bare repository' in GIT?
To co-ordinate with the distributed development and developers team, especially when you are working on a project from multiple computers 'Bare Repository' is used. A bare repository comprises of a version history of your code.
43) How can you fix a broken commit?
To fix any broken commit, you will use the command "git commit—amend". By running this command, you can fix the broken commit message in the editor.
34) What is the function of 'git rm'?
To remove the file from the staging area and also off your disk 'git rm' is used.
How can conflict in git resolved?
To resolve the conflict in git, edit the files to fix the conflicting changes and then add the resolved files by running "git add" after that to commit the repaired merge, run "git commit". Git remembers that you are in the middle of a merger, so it sets the parents of the commit correctly.
Trees?
Tree is an object, which represents a directory. It holds blobs as well as other sub-directories. A tree is a binary file that stores references to blobs and trees which are also named as SHA1 hash of the tree object.
url?
URL represents the location of the Git repository. Git URL is stored in config file.
Version Control System?
Version Control System (VCS) is a software that helps software developers to work together and maintain a complete history of their work. Listed below are the functions of a VCS − Allows developers to work simultaneously. Does not allow overwriting each other's changes. Maintains a history of every version. Following are the types of VCS − Centralized version control system (CVCS). Distributed/Decentralized version control system (DVCS).
What is GIT stash drop?
When you are done with the stashed item or want to remove it from the list, run the git 'stash drop' command. It will remove the last added stash item by default, and it can also remove a specific item if you include as an argument.
35) What is the function of 'git stash apply'?
When you want to continue working where you have left your work, 'git stash apply' command is used to bring back the saved changes onto the working directory.
What does commit object contain?
a) A set of files, representing the state of a project at a given point of time b) Reference to parent commit objects c) An SHAI name, a 40 character string that uniquely identifies the commit object.
5) What are the advantages of using GIT?
a) Data redundancy and replication b) High availability c) Only one.git directory per repository d) Superior disk utilization and network performance e) Collaboration friendly f) Any sort of projects can use GIT
Git rename?
git mv string.c string_operations.c
Git move?
git mv x.txt src/ the move operation moves a directory or a file from one location to another.
Merge two branches?
git push origin newBranch
Git remove?
git rm file
Git stash pop and git stash apply?
git stash pop throws away the (topmost, by default) stash after applying it, whereas git stash apply leaves it in the stash list for possible later reuse (or you can then git stash drop it). This happens unless there are conflicts after git stash pop, in which case it will not remove the stash, leaving it to behave exactly like git stash apply. Another way to look at it: git stash pop is git stash apply && git stash drop.
Git amend?
he amend operation changes the last commit including your commit message; it creates a new commit ID. git commit --amend -m 'Changed'
Git switch branch?
ues the git checkout command to switch between branches
24) What is another option for merging in git?
"Rebasing" is an alternative to merging in git.
What is the function of 'GIT PUSH' in GIT?
'GIT PUSH' updates remote refs along with associated objects. git push <REMOTENAME> <BRANCHNAME> Example: A remote name, for example, origin A branch name, for example, master git push origin master
40) How git instaweb is used?
'Git Instaweb' automatically directs a web browser and runs webserver with an interface into your local repository.
29) What is Subgit? Why to use Subgit?
'Subgit' is a tool for a smooth, stress-free SVN to Git migration. Subgit is a solution for a company -wide migration from SVN to Git that is: a) It is much better than git-svn b) No requirement to change the infrastructure that is already placed c) Allows to use all git and all sub-version features d) Provides genuine stress -free migration experience.
What is a 'conflict' in git?
A 'conflict' arises when the commit that has to be merged has some change in one place, and the current commit also has a change at the same place. Git will not be able to predict which change should take precedence.
33) What is the function of 'git checkout' in git?
A 'git checkout' command is used to update directories or specific files in your working tree with those from another branch without merging it in the whole branch.
What is 'head' in git and how many heads can be created in a repository?
A 'head' is simply a reference to a commit object. In every repository, there is a default head referred as "Master". A repository can contain any number of heads.
2) What is a repository in GIT?
A repository contains a directory named .git, where git keeps all of its metadata for the repository. The content of the .git directory are private to git.
What is 'git status' is used for?
As 'Git Status' shows you the difference between the working directory and the index, it is helpful in understanding a git more comprehensively.
Clone?
Clone operation creates the instance of the repository. Clone operation not only checks out the working copy, but it also mirrors the complete repository. Users can perform many operations with this local repository. The only time networking gets involved is when the repository instances are being synchronized. git clone [email protected]:project.git
1) What is GIT?
GIT is a distributed version control system and source code management (SCM) system with an emphasis to handle small and large projects with speed and efficiency.
What is GIT stash
GIT stash takes the current state of the working directory and index and puts in on the stack for later and gives you back a clean working directory. So in case if you are in the middle of something and need to jump over to the other job, and at the same time you don't want to lose your current edits then you can use GIT stash.
Git life cycle?
General workflow is as follows − You clone the Git repository as a working copy. You modify the working copy by adding/editing files. If necessary, you also update the working copy by taking other developer's changes. You review the changes before commit. You commit changes. If everything is fine, then you push the changes to the repository. After committing, if you realize something is wrong, then you correct the last commit and push the changes to the repository.
How will you know in GIT if a branch has been already merged into master?
Git branch—merged lists the branches that have been merged into the current branch Git branch—-no merged lists the branches that have not been merged
Customize Git Environment?
Git provides the git config tool, which allows you to set configuration variables. Git stores all global configurations in .gitconfig file, which is located in your home directory. To set these configuration values as global, add the --global option, and if you omit --global option, then your configurations are specific for the current Git repository.
Git reset mixed?
Git reset with --mixed option reverts those changes from the staging area that have not been committed yet. It reverts the changes from the staging area only. The actual changes made to the working copy of the file are unaffected. The default Git reset is equivalent to the git reset -- mixed.
Create a Bare Repository?
Let us initialize a new repository by using init command followed by --bare option. It initializes the repository without a working directory. By convention, the bare repository must be named as .git. Git init command creates .git directory to store metadata about the repository every time it reads the configuration from the .git/config file. git --bare init
46) Name a few Git repository hosting services
Pikacode Visual Studio Online GitHub GitEnterprise SourceForge.net
28) Mention some of the best graphical GIT client for LINUX?
Some of the best GIT client for LINUX is a) Git Cola b) Git-g c) Smart git d) Giggle e) Git GUI f) qGit
3) What is the command you can use to write a commit message?
The command that is used to write a commit message is "git commit -a". The -a on the command line instructs git to commit the new content of all tracked files that have been modified. You can use "git add<file>" before git commit -a if new files need to be committed for the first time.
What is the common branching pattern in GIT?
The common way of creating branch in GIT is to maintain one as "Main" branch and create another branch to implement new features. This pattern is particularly useful when there are multiple developers working on a single project.
4) What is the difference between GIT and SVN?
The difference between GIT and SVN is a) Git is less preferred for handling extremely large files or frequently changing binary files while SVN can handle multiple projects stored in the same repository. b) GIT does not support 'commits' across multiple branches or tags. Subversion allows the creation of folders at any location in the repository layout. c) Gits are unchangeable, while Subversion allows committers to treat a tag as a branch and to create multiple revisions under a tag root.
Working Directory and Staging Area or Index?
The working directory is the place where files are checked out. In other CVCS, developers generally make modifications and commit their changes directly to the repository. But Git uses a different strategy. Git doesn't track each and every modified file. Whenever you do commit an operation, Git looks for the files present in the staging area. Only those files present in the staging area are considered for commit and not all the modified files. basic workflow of Git: Step 1 − You modify a file from the working directory. ->(git add) Step 2 − You add these files to the staging area. ->(git commit) Step 3 − You perform commit operation that moves the files from the staging area. After push operation, it stores the changes permanently to the Git repository.
44) Why is it advisable to create an additional commit rather than amending an existing commit?
There are couple of reason a) The amend operation will destroy the state that was previously saved in a commit. If it's just the commit message being changed then that's not an issue. But if the contents are being amended then chances of eliminating something important remains more. b) Abusing "git commit- amend" can cause a small commit to grow and acquire unrelated changes.
41) What does 'hooks' consist of in git?
This directory consists of Shell scripts which are activated after running the corresponding Git commands. For example, git will try to execute the post-commit script after you run a commit.
How can you bring a new feature in the main branch?
To bring a new feature in the main branch, you can use a command "git merge" or "git pull command".
What is the use of 'git log'?
To find specific commits in your project history- by author, date, content or history 'git log' is used.
27) What is GIT version control?
With the help of GIT version control, you can track the history of a collection of files and includes the functionality to revert the collection of files to another version. Each version captures a snapshot of the file system at a certain point of time. A collection of files and their complete history are stored in a repository.
Resolve conflicts?
git -diff -> find difference between files Git commit file
Revert uncommitted changes?
git checkout