Git workflow and interview questions

        Git is an open source distributed version control system that can effectively and quickly handle version management from small to very large projects.

The role played in project development: code management, upload, download, version rollback.....

1. git framework

Refer to the picture of the great god

Two, git workflow

3. How to solve the conflict when submitting?

        reason

        Because when merging branches, someone in the master and dev branches happened to modify the same file, and git didn't know which file to take as the standard, so a conflict occurred.

        solve

        When a conflict occurs, compare the local file with the file on the remote branch, then manually modify the content on the remote branch to the local file, and then submit the conflicting file. Can communicate with and at the same time when necessary.

git stash  //把工作区的修改提交到栈区,目的是保存工作区的修改
git pull  //拉取远程分支上的代码并合并到本地分支,目的是消除冲突
git stash pop  //把保存在栈区的修改部分合并到最新的工作空间中

Fourth, the difference between 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 3rd generation version control tool 2. It belongs to the 2nd generation of version control tools
3. Clients can clone the entire repository on their local system 3. The version history is stored in the server-side repository
4. Submit even offline 4. Only online submissions are allowed
5. Push/pull operations are faster 5. Push/pull operation is slow
6. The project can be shared automatically with commit 6. Nothing is automatically shared

 Five, git function branch operation

master  //默认的主分支
git branch  //查看本地分支
git branch 分支名称  //新建分支
git checkout 分支名称  //切换分支
git checkout -b 本地分支名  //切换分支
git checkout origin 远程分支名  //切换分支
git branch -r   //查看远程仓库的分支
git push --set-upstream origin 分支名称  //本地分支提交到远程仓库
git branch -d 分支名称  //删除本地分支
git push origin --delete 分支名称  //删除远程仓库的分支

6. Merge branch method

        git merge branchname

        If it is currently written under the master branch: git merge dev, then master and dev will be merged, which is equivalent to master + dev.

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

        Remove or fix bad files in a new commit and push it to the remote repository.

git commit -m "commit message"

        Create a new commit, undoing all changes made in the bad commit.

git revert <name of bad commit>

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

        The git pull command pulls 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 do a git fetch, it fetches all new commits from the desired branch and stores them in a new branch in your local repository. If you want these changes to be reflected in the target branch, you must do a git merge after the git fetch. The target branch is only updated after a merge has been done between the target branch and the fetched branch.

git pull = git fetch + git merge

Nine, other common commands

git diff index.js   //查看某一个修改文件
git diff   //查看所有修改文件
git log   //查看修改历史
git reflog   //查看修改历史【简单形式】
git reset --hard HEAD^   //回到上一个版本
git reset --hard 版本号   //回到指定版本

 Ten, gitflow workflow

        The gitflow process uses a central code repository, which is the clearinghouse for all developers. Like other workflows, developers complete the development locally, and then push the branch code to the central warehouse. The only difference is the structure of the branches in the project.

serial number

name

content

1

master

Used to save the online version code and create a dev branch

2

develop

Used to save the relatively stable version of the code, all features are created by the dev branch

3

feature

Used to develop certain functions, different functions may create different branches

4

release

It is used to prepare the code before going online (testing, bug fixing), and is created by dev

5

bugfix

Used to fix non-urgent bugs

6

hotfix

for urgent bug fixes

A picture from the Great God

 

 

Guess you like

Origin blog.csdn.net/m0_73460278/article/details/126669347