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

What are the Git interview questions of Java?

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "what are the Git interview questions of Java". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the Git interview questions for Java"?

Question 1: what is Git fork? What is the difference between fork, branch, and clone?

Fork is a remote, server-side copy of a repository, which is different from the source. Engraving is not really the category of Git. It's more like a political / social concept.

Clone is not a copy, it is a local copy of a remote repository. When you clone, you actually copy the entire source repository, including all history and branches.

Branch is a mechanism for handling changes in a single repository and ultimately for merging with other parts of the code.

Question 2: what is the difference between "pull request" and "branch"?

A branch is a separate version of the code.

A pull request (pull request) is when someone uses the repository, sets up their own branch, makes some changes, and merges them into that branch (applying their own changes to someone else's code repository).

Question 3: what is the difference between "git pull" and "git fetch"?

Simply put, git pull is git fetch + git merge.

When you use pull,Git, you will try to finish the work for you automatically. It is context-sensitive, so Git will merge all pulled submissions into the branch you are currently working on. Pull is a process that automatically merges and submits without allowing you to review it. If you don't manage your branch carefully, you may encounter conflicts frequently.

When you fetch,Git collects all non-existent commits in the target branch and stores them in the local repository. However, Git does not merge these commits into the current branch. This processing logic is useful when you need to keep the warehouse up-to-date and want to deal with possible interruptions when updating files. If you merge the submission into the main branch, you should use merge.

Question 4: explain the advantages of Forking workflow

The Forking workflow is fundamentally different from other popular Git workflows. Instead of using a single server-side repository as a "central" code base, it provides each developer with his own server-side repository. Forking workflows are most commonly used in public open source projects.

The main advantage of the Forking workflow is that it can aggregate submission contributions without the need for each developer to submit to a central repository, thus achieving a clean project history. Developers can push code to their own server repository, while only project maintainers can push code directly to the official repository.

When developers are ready to publish local submissions, their submissions are pushed to their own public repositories, not official repositories. They then submit a request for pull request to the main warehouse, which informs the project maintainer that there are updates that can be integrated.

Question 5: tell me the difference between HEAD, working tree and index in Git?

The working tree / working directory / workspace is the directory tree of the (source) files you see and edit.

The index / transit area (staging area) is a single, large binary file in / .git / index that lists the SHA1 checksum, timestamp and file name of all files in the current branch, not a directory with a copy of the file.

HEAD is the last committed reference / pointer of the currently checked out branch.

Question 6: can you explain the Gitflow workflow?

The Gitflow workflow uses two parallel, long-running branches to record the history of the project, namely the master and develop branches.

Master, a branch of the online version that is ready to be released, all of its content has been fully tested and approved (production ready).

The Hotfix, maintenance or hotfix branch is used to patch quick fixes to production versions. Hotfix branches are much like release branches and feature branches, unless they are based on master rather than develop branches.

Develop is a branch that merges all feature branches and performs all tests. Only after everything has been thoroughly checked and repaired can it be merged into the master branch.

Feature, each function should be developed in its own branch, can be pushed to the develop branch as the parent branch of the function (feature) branch.

Question 7: when should I use "git stash"?

The git stash command saves your uncommitted changes (staged and unstaged) for later use and can be restored from the working copy later.

Review:

$git status

On branch master

Changes to be committed:

New file: style.css

Changes not staged for commit:

Modified: index.html

$git stash

Saved working directory and index state WIP on master: 5002d47 our new homepage

HEAD is now at 5002d47 our new homepage

$git status

On branch master

Nothing to commit, working tree clean

One place we can use stash is if we find that we forgot something in the last commit and have already started working on the next commit in the same branch:

# Assume the latest commit was already done

# start working on the next patch, and discovered I was missing something

# stash away the current mess I made

$git stash save

# some changes in the working dir

# and now add them to the last commit:

$git add-u

$git commit-ammend

# back to work!

$git stash pop

Question 8: how do I delete a file from the git without deleting it from the file system?

If you misoperate during the git add process, you will eventually add files that you do not want to submit. However, git rm will delete your files from your scratch area (index) and file system (working tree), which may not be what you want. Replace it with git reset operation:

Git reset filename # or

Echo filename > > .gitingore # add it to .gitignore to avoid re-adding it

What it means is that git reset is the inverse of git add.

Question 10: when to use "git rebase" instead of "git merge"?

Both commands integrate changes from one branch to another, but they are done in very different ways. Consider the scenario, before merging and rebasing:

A

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

Development

Wechat

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

12
Report