Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Sample interview questions for Git2

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

The editor will share with you some examples of Git2 interview questions. I hope you will get something after reading this article. Let's discuss it together.

The first question about the Git interview must be:

1. What's the difference between Git and SVN?

GitSVN1. Git is a distributed version control tool 1. SVN is a centralized version control tool 2. It belongs to the third generation version control tool 2. It belongs to the second generation version control tool 3. The client can clone the entire repository on its local system. Version history is stored in the server-side repository 4. 5. You can submit 4. 4 even offline. Only online submission is allowed for faster 5.Push/pull operations and slower 5.Push/pull operations 6. 5%. The project can be automatically shared with commit. Nothing is automatically shared.

two。 What is Git?

I suggest you answer this question by understanding the architecture of git, as shown in the following figure, try to explain this diagram:

● Git is a distributed version control system (DVCS). It tracks changes to files and allows you to revert to any specific version of the changes.

Compared with other version control systems (VCS) such as SVN, ● has many advantages in its distributed architecture. One of the main advantages is that it does not rely on a central server to store all versions of project files.

● every developer can "clone" a copy of the repository I marked with "Local repository" in the figure, and has a complete history of the project on his hard drive, so when the server goes down, all the recovery data you need is in your teammate's local Git repository.

● also has a central cloud repository to which developers can commit changes and share them with other team members, as shown in the figure, all collaborators are committing changes to the "remote repository".

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

3. What is the command submitted in Git?

The answer is very simple.

The command for write commit is git commit-a.

Now explain the-a flag and instruct git to submit the new contents of all tracked files that have been modified by adding-a to the command line. Also mention that if this is the first time you need to submit a new document, you can git add it before git commit-a.

4. What is a "naked repository" in Git?

You should explain the difference between a "working directory" and a "naked repository".

The "naked" repository in Git contains only version control information and no working files (no working tree), and it does not contain special .git subdirectories. Instead, it contains everything in the .git subdirectory directly in the home directory itself, where the working directory includes:

1. A .git subdirectory that contains all the relevant Git revision history of your warehouse.

two。 The work tree, or a copy of the checked out project file.

5. What language is Git written in?

You need to explain why you use it, not just the name of the language. I suggest you answer like this:

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

6. In Git, how do you restore a submission that has been push 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 depending on the situation: 1

There can be two answers to this question, and be sure to include them when you answer them, because the following options can be used depending on the situation:

● deletes or fixes the error file in the new submission and pushes it to the remote repository. This is the most natural way to fix errors. After making the necessary modifications to the file, submit it to the remote repository I will use

Git commit-m "commit message"

● creates a new commit and undoes all changes made in the error commit. You can use the command:

Git revert

7. What's the difference between git pull and git fetch?

The git pull command extracts new changes or commits for a specific branch from the central repository and updates the target branch in the local repository.

Git fetch is also used for the same purpose, but it works slightly differently. When you execute git fetch, it extracts all new commits from the required branches and stores them in a new branch in the local repository. If you want to reflect these changes in the target branch, you must perform git merge after git fetch. The target branch is updated only after the target branch and the acquired branch are merged. For convenience, remember the following equation:

Git pull = git fetch + git merge

8. What is the word "staging area" or "index" in git?

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

This can be explained by the following figure:

Before completing the submission, it can be formatted and reviewed in an intermediate area called "staging area" or "index". As you can see from the figure, each change is first validated in the staging area, which I call "stage file", and then commits the change to the repository.

9. What is git stash?

The necessity of git stash should be explained first.

Usually, when you have been working on a part of the project, if you want to switch branches at some point to deal with other things, things will be in a chaotic state. The problem is that you don't want to submit half-finished work so that you can go back to your current job later. The answer to this problem is git stash.

Then explain what git stash is.

Stash saves your working directory, that is, modified tracking files and temporary changes, in a pile of outstanding changes, which you can reapply at any time.

10. What is git stash drop?

Answer this question by explaining the purpose of using git stash drop.

The git stash drop command is used to delete hidden items. By default, it deletes the last added storage item, and it can delete specific items if parameters are provided.

Let me give you an example.

If you want to remove a specific storage item from the list of hidden items, you can use the following command:

Git stash list: it 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: 21d80a5 added number to log

If you want to delete the project named stash@ {0}, use the command git stash drop stash@ {0}.

11. How do I find a list of files that have changed in a particular submission?

For this problem, you can't just provide a command, but also explain what the command does.

To get the list files that have changed in a specific submission, use the following command:

Git diff-tree-r {hash}

Given a commit hash, this lists all files that were changed or added to the commit. The-r flag causes the command to list individual files instead of just collapsing them into the root directory name.

You can also include the content mentioned below, which is optional but helps to impress the interviewer.

The output will also contain some additional information that can be easily shielded by including two flags:

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

Here-no-commit-id will prevent submission hashes from appearing in the output, while-name-only will only print file names, not their paths.

12. What is the function of git config?

First of all, explain why we need git config.

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

Let's use an example to explain.

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

Git config-global user.name "Your Name": this command adds a user name.

Git config-global user.email "Your E-mail Address": this command adds an email ID.

13. What does the submission object contain?

The Commit object contains the following components, and you should mention the following three points:

● a set of files that represent the status of a project at a given point in time

● refers to the parent submission object

The ● SHAI name, a 40-character string that uniquely identifies the submitted object.

14. How do I create a repository in Git?

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

To create the repository, first create a directory for the project (if it does not already exist), and then run the command git init. By running this command, the .git directory is created in the project's directory.

15. How to compress N submissions into one submission?

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

● if you want to write a new submission message from scratch, use the following command:

Git reset-soft HEAD~N & & git commit

● if you want to concatenate existing commit messages in new submission messages, 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})"

16. What is Git bisect? How do you use it to determine (regression) the source of the error?

I suggest you give a small definition of Git bisect first.

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

Git bisect

Now that you have mentioned the above command, explain what it will do.

This command uses a binary search algorithm to find which submission in the project history introduced an error. You can use it by telling it the "error" submission that is known to contain the error and the "good" submission that was known before the error was introduced. Git bisect then chooses a commit between the two endpoints and asks whether the submission you selected is "good" or "bad". It continues to narrow it down until it finds the exact commit that introduced the change.

17. How do I configure the Git repository if I want to run the code check tool before committing and block commits if the test fails?

I suggest you introduce the integrity check first.

Integrity or smoke testing is used to determine whether it is feasible and reasonable to continue the test.

The following explains how to achieve this goal.

This can be done through a simple script related to the pre-commit hook of the repository. Git triggers pre-commit hook before committing. You can run other tools in this script, such as linters, and perform integrity checks on changes committed to the repository.

Finally, as an example, you can refer to the following script:

#! / bin/shfiles=$ (git diff- cached-name-only-diff-filter=ACM | grep '.go $') if [- z files]; then exit 0fiunfmtDNA $(gofmt-l $files) if [- z unfmtd]; then exit 0fiecho "Some .go files are not fmt'd" exit 1

This script checks to see if all the soon-to-be submitted .go files need to be delivered through the standard Go source code formatter gofmt. If the step exits in a non-zero state, the script effectively blocks the commit operation.

18. Describe the branching strategy you use?

This question was asked to test your branch experience with Git, telling them how you used the branch in your previous work and what its purpose was. You can refer to the following points:

● function Branch (Feature branching)

The feature branch model retains all changes to a specific feature within the branch. When the functionality is fully tested and verified by automated testing, the branch is merged into the primary server.

● Task Branch (Task branching)

In this model, each task is implemented on its own branch, with the task key contained in the branch name. It's easy to see which code implements which task, just look for the task key in the branch name.

● release Branch (Release branching)

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

Finally, I told them that branching strategies vary from team to team, so I know the basic branching operations, such as deleting, merging, checking branches, and so on.

19. If the branches have been merged into master, how can you know?

The answer is straightforward.

To know whether a branch has been merged into a master, you can use the following command:

Git branch-merged, which lists the branches that have been merged into the current branch.

Git branch-no-merged, which lists branches that have not yet been merged.

20. 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 whenever you want.

This has many advantages, such as you can quickly import from Subversion to Git or use SubGit in Atlassian Bitbucket Server. We can use SubGit to create a two-way Git-SVN image of an existing Subversion repository. You can push to Git or submit Subversion at your convenience. Synchronization is done by SubGit.

After reading this article, I believe you have a certain understanding of "sample Git2 interview questions". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report