3. Crazy geek

Original: https://www.edureka.co/blog/i…


Without permission, no reprint! This article first send WeChat messages public number: front-end pioneer welcome attention, every day to you push fresh front-end technology articles


I love Git at work. Git plays an important role in many development teams.

The first question about a Git interview must be:

What’s the difference between q1.git and SVN?

Git SVN
1. Git is a distributed version control tool 1. SVN is a centralized version control tool
2. It belongs to the third generation of version control tools 2. It belongs to the second generation of version control tools
3. Clients can clone the entire repository on their local system Version history is stored in a server-side repository
4. You can submit even offline 4. Only online submissions are allowed
5.Push/pull operation is faster 5.Push/pull operation is slow
Projects can be shared automatically with COMMIT 6. Nothing is automatically shared

Q2. What is Git?

I encourage you to answer this question by looking at Git’s architecture, as shown in the diagram below, and trying to explain the diagram:

  • Git is a distributed version control system (DVCS). It tracks changes to files and allows you to revert to changes made in any particular version.
  • Its distributed architecture has many advantages over other version control systems (VCS) such as SVN, one of the main advantages being that it does not rely on a central server to store all versions of a project’s files.
  • Each developer can “clone” a copy of the repository I’ve labeled “Local Repository” in the diagram, and has a complete history of the project on his hard drive, so all the recovery data you need in the event of a server outage is in your teammate’s Local Git repository.
  • There is also a central cloud repository to which developers can commit changes and share them with other team members, as shown in the figure, where all collaborators are committing changes to the “remote repository.”

The next set of Git interview questions will test your experience with Git:

Q3. What is the command to commit in Git?

The answer is very simple. The command used to write the commit is git commit-a.

Now explain the -a flag, which instructs Git to commit the new contents of any trace files that have been modified by adding -a to the command line. Also, if this is the first time you need to commit a new file, you can start git add

before committing to git -a.

Q4. What is a “naked repository” in Git?

You should clarify the difference between a “working directory” and a “bare repository.”

The “naked” repository in Git contains only version control information and no working files (no working tree), and it does not contain a special.git subdirectory. Instead, it contains all the contents of the.git subdirectory directly in the home directory itself, where the working directories include:

  1. a.gitA subdirectory that contains all relevant Git revision history for your repository.
  2. Work tree, or a copy of the checked out project file.

Q5. What language is Git written in?

You need to explain why you’re using it, not just the name of the language. I suggest you respond by saying:

Git is written in C. Git is fast, and C does this by reducing runtime overhead.

Q6. In Git, how do you restore a commit that has been pushed and made public?

There can be two answers to this question and make sure that you include both because any of the below options can be Used on the situation depending on the situation: 1 This question can have two answers. Be sure to include them as well, depending on the situation you can use the following options:

  • Delete or fix the wrong file in the new commit and push it to the remote repository. This is the most natural way to fix a mistake. After making the necessary changes to the file, commit it to the remote repository I’ll be using
git commit -m "commit message"
  • Create a new commit that undoes any changes made in the wrong commit. You can use the command:
git revert <name of bad commit>

Q7. What is the difference between git pull and git fetch?

The Git Pull command pulls new changes or commits for a particular branch from the central repository and updates the target branch in the local repository.

Git Fetch is used for the same purpose, but it works slightly differently. When you perform Git Fetch, it fetches all new commits from the required branch and stores them in the new branch in the local repository. If you want to reflect these changes in the target branch, you must perform a Git Merge after Git Fetch. The target branch is updated only after the target branch and the acquired branch have been merged. For convenience, remember the following equation:

<center><h5>git pull = git fetch + git merge</h5></center>

Q8. What is the “staging area” or “index” in git?

For this answer try to explain the below diagram as you can see:

Before the commit is complete, it can be formatted and reviewed in a middle area called the “staging area” or “index.” As you can see from the figure, each change is first validated in the staging area, which I call a “stage file,” and then the changes are committed to the repository.

Q9. What is Git Stash?

You should first explain why Git Stash is necessary.

Often, when you’ve been working on one part of a project, if you want to switch branches at some point to work on something else, things will get chaotic. The problem is, you don’t want to submit half-done work so that you can go back to the current work later. The answer to this problem is Git Stash.

Explain what Git Stash is.

Stash saves your working directory, the modified trace files and the pending changes, in a pile of unfinished changes that you can reapply at any time.

Q10. What is a git stash drop?

Answer this question by explaining why we are using Git Stash Drop.

The git stash drop command is used to delete hidden items. By default, it deletes the last storage item added, and it can also remove specific items if you provide a parameter.

Here’s an example.

To remove a specific storage item from the list of hidden items, use the following command:

Git Stash List: This will show a list of hidden items such as:

stash@{0}: WIP on master: 049d078 added the index file stash@{1}: WIP on master: C264051 Revert “Added File_Size” STASH @{2}: WIP on Master: Added Number to Log

To delete an item named stash@{0}, use the command git stash drop stash@{0}.

Q11. How do I find the list of files that have changed in a particular commit?

In this case, you can’t just provide the command, but explain what the command actually does.

To get the list files that have changed in a particular commit, use the following command:

git diff-tree -r {hash}

Given a commit hash, this lists all files that have been changed or added in that commit. The -r flag causes the command to list individual files, rather than just folding them into the root directory name.

You can also include the following, which, while optional, will help impress the interviewer.

The output will also contain some additional information, which can be easily masked by including two flags:

Git diff-tree — no-commit-id — name-only-r {hash}

Here -no-commit-id disallows commit hashes from appearing in the output, and -name-only prints only filenames, not their paths.

Q12. What is the function of git config?

Let’s start by explaining why we need Git Config.

Git uses your username to associate a commit with your identity. The git config command can be used to change your git configuration, including your user name.

Here’s an example to illustrate.

Suppose you want to provide a username and email ID to associate a submission with an identity, so that you can know who made a particular submission. To do this, I will use:

Git config — global user.name “Your name “: This command will add the user name.

Git config — global user. Email “Your E-mail Address”: This command will add an E-mail ID.

Q13. What does the submission object contain?

The Commit object contains the following components, three of which you should mention:

  • A set of files representing the state of the project at a given point in time
  • References the parent submission object
  • The SHAI name, a 40-character string that uniquely identifies the submitted object.

Q14. How do I create a repository in Git?

This is probably the most common question, and the answer is simple.

To create a repository, create a directory for your project (if it doesn’t exist) and then run the command git init. By running this command, the.git directory is created in the project’s directory.

Q15. How to compress N commits into a single commit?

There are two ways to compress N commits into a single commit:

  • To write a new commit message from scratch, use the following command:
Git reset -- soft HEAD~N && git commit
  • If you want to concatenate existing commit messages in a new commit message, then you need to extract these messages and pass them to Git Commit, like this:
Git reset -- soft HEAD~N && git commit -- edit-m "$(git log -- format=%B -- reverse.head @{N})"

Q16. What is Git bisect? How can it be used to determine the source of the (regression) error?

I suggest you start with a small definition of Git bisect.

Git bisect is used to find submissions that introduce errors using binary search. Git Bisect’s command was

git bisect <subcommand> <options>

Now that you have mentioned the above command, explain what this command does.

This command uses a binary search algorithm to find which commit in the project history introduced the error. You can use it by telling it that you know the “wrong” commit that contains the error and that you know the “good” commit before the error was introduced. Git Bisect then selects a commit between these two endpoints and asks you if your selected commit is “good” or “bad.” It continues to narrow down until it finds the exact commit to which the change was introduced.

Q17. How do I configure a Git repository if I want to run a code checker before committing and block committing if my tests fail?

I suggest you introduce integrity checking first.

The completeness or smoke test is used to determine whether further testing is feasible and reasonable.

Here’s how to do it.

This can be done through a simple script associated with the repository’s pre-commit hooks. Git triggers a pre-commit hook before committing. You can run other tools, such as linters, from the script and perform integrity checks on changes committed to the repository.

As a final example, you can look at the following script:

#! / bin/sh files = $(git diff - cached - name - only - the diff - filter = ACM | grep '. Go $') if [files] - z; then exit 0 fi unfmtd=$(gofmt -l $files) if [ -z unfmtd ]; Then exit 0 fi echo "Some. Go files are not FMT'd" exit 1

This script checks to see if you need to pass all of the upcoming.go files through the standard Go source formatting tool, gofmt. If the step exits with a non-zero state, the script effectively prevents the commit operation.

Q18. Describe the branching strategy you used?

This question asks you to test your branching experience with Git and tell them how you used branches in your previous work and what they were used for. You can refer to the points mentioned below:

  • Feature Branching

    The element branch model keeps all changes to a particular element in the branch. When the functionality is fully tested and validated through automated tests, this branch is merged into the primary server.

  • Task Branching

    In this model, each task is implemented on its own branch, and the task key is contained in the branch name. It’s easy to see which code implements which task by looking for the task key in the branch name.

  • Release Branching

    Once the development branch has sufficient publishing capabilities, you can clone the branch to form the publishing branch. Creating this branch will start the next release cycle, so no new functionality can be added after this point, only bug fixes, document generation, and other release-oriented tasks should be included in this branch. Once it is ready for release, the version is merged into the primary server and marked with a version number. In addition, it should incorporate the progress that has been made since release back into the development branch.

Finally, tell them that branching policies vary from team to team, so I know the basic branching operations, such as deleting, merging, checking branches, etc.

Q19. How do you know if a branch has been merged into a master?

The answer is straightforward.

To find out if a branch has been merged as master, you can use the following command:

Git branch – merged This lists branches merged into the current branch.

Git branch — no-merged This lists branches that have not been merged.

Q20. What is SubGit?

Subgit is a tool for migrating SVN to Git. It creates a writable Git image of a local or remote Subversion repository, and you can use Subversion and Git as much as you like.

There are many advantages to doing this, such as the ability to quickly import Git from Subversion in one go or to use Subgit in the Atlassian Bitbucket Server. You can use Subgit to create a bi-directional git-svn image of an existing Subversion repository. You can push to Git or commit to Subversion at your convenience. The synchronization is done by SubGit.


This article first send WeChat messages public number: front-end pioneer

Welcome to scan the two-dimensional code to pay attention to the public number, every day to push you fresh front-end technology articles


Read on for the other great articles in this column:

  • 12 Amazing CSS Experiment Projects
  • 50 React Interview Questions You Must Know
  • What are the front-end interview questions at the world’s top companies
  • 11 of the best JavaScript dynamic effects libraries
  • CSS Flexbox Visualization Manual
  • React from a designer’s point of view
  • The holidays are boring? Write a little brain game in JavaScript!
  • How does CSS sticky positioning work
  • A step-by-step guide to implementing animations using HTML5 SVG
  • Programmer 30 years old before the monthly salary is less than 30K, which way to go
  • 14 of the best JavaScript data visualization libraries
  • 8 top VS Code extensions for the front end
  • A complete guide to Node.js multithreading
  • Convert HTML to PDF 4 solutions and implementation

  • More articles…