Q1. What is Git?
Git is a version control system for tracking changes in computer files and is used to help coordinate work among several people on a project while tracking progress over time. In other words, it’s a tool that facilitates source code management in software development.
2. What do you understand by the term ‘Version Control System’?
A VCS keeps track of the contributions of the developers working as a team on the projects. They maintain the history of code changes done and with project evolution, it gives an upper hand to the developers to introduce new code, fix bugs, and run tests with confidence that their previously working copy could be restored at any moment in case things go wrong.
Q3. What is a Git repository?
Git repository refers to a place where all the Git files are stored. These files can either be stored on the local repository or on the remote repository.
Q4. What does git clone do?
The command creates a copy (or clone) of an existing git repository. Generally, it is used to get a copy of the remote repository to the local repository.
Q5. What does the command git config do?
The git config command is a convenient way to set configuration options for defining the behavior of the repository, user information and preferences, git installation-based configurations, and many such things.
For example:
To set up your name and email address before using git commands, we can run the below commands:
git config --global user.name “<<your_name>>”
git config --global user.email “<<your_email>>”
Q6. What is a conflict?
Git usually handles feature merges automatically but sometimes while working in a team environment, there might be cases of conflicts such as:
1. When two separate branches have changes to the same line in a file
2. A file is deleted in one branch but has been modified in the other.
These conflicts have to be solved manually.
Q7. What is the functionality of git ls-tree?
This command returns a tree object representation of the current repository along with the mode and the name of each item and the SHA-1 value of the blob.
Q8. What does git status command do?
git status command is used for showing the difference between the working directory and the index which is helpful for understanding git in-depth and also keep track of the tracked and non-tracked changes.
Q9. What does git add command do?
This command adds files and changes to the index of the existing directory.
You can add all changes at once using git add . command.
You can add files one by one specifically using git add <file_name> command.
You can add contents of a particular folder by using git add /<folder_name>/ command.
Q10. Why is it considered to be easy to work on Git?
1). Branching Capabilities:
-Due to its sophisticated branching capabilities, developers can easily work on multiple branches for the different features of the project.
-It also has an easier merge option along with an efficient work-flow feature diagram for tracking it.
2) Distributed manner of development:
- Git is a distributed system and due to this nature, it became easier to trace and locate data if it's lost from the main server.
- In this system, the developer gets a repository file that is present on the server. Along with this file, a copy of this is also stored in the developer’s system which is called a local repository.
- Due to this, the scalability of the project gets drastically improved.
3) Pull requests feature:
- This feature helps in easier interaction amongst the developers of a team to coordinate merge-operations.
- It keeps a proper track of the changes done by developers to the code.
4) Effective release cycle:
- Due to the presence of a wide variety of features, git helps to increase the speed of the release cycle and helps to improve the project workflow in an efficient manner.
Q11. How will you create a git repository?
Then in order to create a git repository, create a folder for the project and then run git init.
Doing this will create a .git file in the project folder which indicates that the repository has been created.
Q12. Tell me something about git stash?
Git stash can be used in cases where we need to switch in between branches and at the same time not wanting to lose edits in the current branch. Running the git stash command basically pushes the current working directory state and index to the stack for future use and thereby providing a clean working directory for other tasks.
Q13. What is the command used to delete a branch?
To delete a branch we can simply use the command git branch –d [head].
To delete a branch locally, we can simply run the command: git branch -d <local_branch_name>
To delete a branch remotely, run the command: git push origin --delete <remote_branch_name>
Q14. What differentiates between the commands git remote and git clone?
git remote command creates an entry in git config that specifies a name for a particular URL. Whereas git clone creates a new git repository by copying an existing one located at the URL.
Q15. What does git stash apply command do?
git stash apply command is used for bringing the works back to the working directory from the stack where the changes were stashed using git stash command.
This helps the developers to resume their work where they had last left their work before switching to other branches.
Q16. Differentiate between git pull and git fetch.
git pull:
This command pulls new changes from the currently working branch located in the remote central repository.
git fetch:
This command is also used for a similar purpose but it follows a two step process:
1. Pulls all commits and changes from desired branch and stores them in a new branch of the local repository.
current
2. For changes to be reflected in the current / target branch, git fetch should be followed by git merge command.
git pull = git fetch + git merge
Q17. Can you give differences between “pull request” and “branch”?
pull request: This process is done when there is a need to put a developer’s change into another person’s code branch.
branch: A branch is nothing but a separate version of the code.
Q18. What do the git diff and git status commands do?
git diff: This shows the changes between commits, working trees, etc.
git status: This shows the difference between the working directory and index that is essential in understanding git in depth.
Q19. What has to be run to squash multiple commits (last N) into a single commit?
Use the below command to write a new commit message from the beginning.
git reset -soft HEAD~N &&git commit
But, if you want to edit a new commit message and add the existing commit messages, then you must extract the messages and pass them to Git commit.
The below command will help you achieve this:
git reset -soft HEAD~N &&git commit -edit -m“$(git log -format=%B -reverse .HEAD@{N})”
Q20. How would you recover a branch that has already pushed changes in the central repository but has been accidentally deleted from every team member’s local machines?
We can recover this by checking out the latest commit of this branch in the reflog and then checking it out as a new branch.
Q21. What is git stash drop?
The Git stash drop command is used to remove a particular stash. If there’s a stash you're no longer using or you want to remove a specific item of stash from the list, you can use the stash commands.
Let’s say you want to delete an item named stash@{abc}; you can use the command:
git stash drop stash@{abc}.
Q22. What’s the difference between reverting and resetting?
Reverting: The revert command in Git is used to create a new commit that undoes the changes made in the previous commit. When you use this command, a new history is added to the project; the existing history is not modified.
Resetting: Git reset is a command that is used to undo the local changes that have been made to a Git repository. Git reset operates on the following: commit history, the staging index, and the working directory.
Q23. How can you discover if a branch has already been merged or not?
There are two commands to determine these two different things.
git branch --merged - Returns the list of branches that have been merged into the current branch.
git branch --no-merged - Returns the list of branches that have not been merged.
Q24. What is “git cherry-pick”?
The command git cherry-pick enables you to pick up commits from a branch within a repository and apply it to another branch. This command is useful to undo changes when any commit is accidentally made to the wrong branch. Then, you can switch to the correct branch and use this command to cherry-pick the commit.
Q25. What is the command used to fix a broken commit?
To fix a broken commit in Git, you may use the “git commit --amend” command, which helps you combine the staged changes with the previous commits instead of creating an entirely new commit.
Q26. What is the difference between fork, branch, and clone?
Fork: The fork is the process when a copy of the repository is made. It's usually experimentation in the project without affecting the original project. They’re used to advise changes or take inspiration from someone else’s project.
Branch: Git branches refer to individual projects within a git repository. If there are several branches in a repository, then each branch can have entirely different files and folders.
Clone: Git clone refers to creating a clone or a copy of an existing git repository in a new directory. Cloning automatically creates a connection that points back to the original repository, which makes it very easy to interact with the central repository.
Q27. Explain the different points when a merge can enter a conflicted stage.
There are two stages when a merge can enter a conflicted stage.
1. Starting the merge process
If there are changes in the working directory of the stage area in the current project, the merge will fail to start. In this case, conflicts happen due to pending changes that need to be stabilized using different Git commands.
2. During the merge process
The failure during the merge process indicates that there’s a conflict between the local branch and the branch being merged. In this case, Git resolves as much as possible, but some things have to be fixed manually in the conflicted files.
Q28. What is Git Bisect and how do you use it?
The Git Bisect command performs a binary search to detect the commit which introduced a bug or regression in the project’s history.
Syntax: git bisect <subcommand> <options>
Q29. How do you find a list of files that has been changed in a particular commit?
The command to get a list of files that has been changed in a particular commit is:
git diff-tree –r {commit hash}
-r flag allows the command to list individual files
commit hash lists all the files that were changed or added in the commit.
Q30. What is the functionality of git clean command?
The git clean command removes the untracked files from the working directory.
Q31. If you recover a deleted branch, what work is restored?
The files that were stashed and saved in the stashed index can be recovered. The files that were untracked will be lost. Hence, it's always a good idea to stage and commit your work or stash them.
Q32. What does the git reset --mixed and git merge --abort commands do?
git reset --mixed is used to undo changes made in the working directory and staging area.
git merge --abort helps stop the merge process and return back to the state before the merging began.
Q33. What is the process to revert a commit that has already been pushed and made public?
There are two processes through which you can revert a commit:
1. Remove or fix the bad file in a new commit and push it to the remote repository. Then commit it to the remote repository using:
git commit –m “commit message”
2. Create a new commit to undo all the changes that were made in the bad commit. Use the following command:
git revert <commit id>
Q34. What does the git push command do?
The Git push command is used to push the content in a local repository to a remote repository. After a local repository has been modified, a push is executed to share the modifications with remote team members.
Git-push-command
Q35. Which language is used in Git?
Git is a fast and reliable version control system, and the language that makes this possible is ‘C.’
Using C language reduces the overhead of running times, which is common in high-level languages.
No comments:
Post a Comment