Home > Development Tools > git > body text

Git tutorial notes organization (summary sharing)

WBOY
Release: 2022-03-17 18:18:41
forward
2093 people have browsed it

This article brings you relevant knowledge about Git, mainly the compilation of git tutorial notes, including version controller methods, installation, basic operations and operating instructions, etc. I hope Helpful to everyone.

Git tutorial notes organization (summary sharing)

Recommended study: "Git Tutorial"

1. Version Controller Method

1.1 Actual scenario

Backup code restoration collaborative development traceability code issues

1.2 Version control method

  1. Centralized version Control tools SVN and CVS
    Everyone downloads the code from the central server, and submits the modifications to the central server.
  2. Distributed version control tool git
    Everyone’s computer has a complete library, and each other can see each other’s changes.
    Git tutorial notes organization (summary sharing)
##2. Installation

    Explanation:
  1. · Git GUI: The graphical interface tool provided by Git
    · Git Bash: Git The command line tool provided
  2. After installation, set up the email first (the email identifies different people):
  3. Open Git Bash—
    Set the person
    git config --global user.name "name " Set up email
    git config --global user.email "email"
  4. can be viewed through
  5. git config --global user.name Whether the setting is successful
3. Start the operation

3.1 Create a local warehouse

1) Create an empty directory as a local Git warehouse

2) Enter this directory and right-click to open the Git bash window
3) Execute the command
git init 4) After the creation is successful, you can see the hidden .git directory under the folder
You can view the basic operations of
Part 4 later

3.2 Branches

Almost all version controls support branches. Everyone has an independent branch, and development does not affect each other. When finished, merge them together. HEAD points to the current branch, and modifications will only change the contents of the current branch.


git branch View branch
git branch nameCreate name branch
git checkout branch name Switch branch git checkout -b Branch name Create and switch
git merge Branch name 1 Merge branch Branch 1 merges with the current branch If
different branches conflict: they will not be merged automatically , storing different versions of information in files requires manual selection
git branch -d nameDelete name branch-DForce deletion

3.3 Git remote Warehouse

Commonly used are GitHub, Code Cloud, and GitLab (commonly used by enterprises). The course uses Code Cloud as an example.

1) Open the gitee web page to log in - create a new warehouse -
2) Configure the SSH public key:

    Enter
  1. ssh-keygen -t rsa in bash (continuous Press Enter to automatically overwrite if the public key already exists)
  2. cat ~/.ssh/id_rsa.pubGet the public key - copy the output public key - open gitee's user-settings-SSH Public key
  3. Verify whether the configuration is successful:
  4. ssh -T git@gitee.com
3) Connect to the local warehouse

    Open the warehouse created on gitee and copy SSH (the address of the remote warehouse)
  1. In bash
  2. git remote add name (the name you set) ssh address Note that you need to before this git init
  3. Check whether the configuration is successful
  4. git remote It will be successful if the name you set appears
  5. Local code upload
  6. git push [local branch name] :[Remote branch name] Note that you must submit it in the local warehouse before doing this The complete code is
    git push [-f] [--set-upstream][Remote name] [Local branch name]: [remote branch name] [-f]: Force overwriting of remote code
    [–set-upstream] means establishing an association between local and remote branches
    Remote branch If the name is the same as the local
    , it can be omitted: [remote branch name] If both are associated , then [local branch name] can be omitted: [remote branch name]
  7. 4) Other operations
  1. Clone from the remote warehousegit clone <warehouse path> [Local path]</warehouse>
  2. Fetch from the remote warehousegit fetch [remote name] [ branch name]
    will capture the updates in the warehouse locally and will not merge them. If the remote name and branch name are not specified, all branches will be fetched and the current branch will be updated. If you need to merge, you needgit merge [remote name]
  3. pull commandgit pull [remote name] [branch name] That is, grab and merge
  4. Resolve Merge Conflicts
    After AB is cloned from the remote end, A will modify it locally and then push it to the remote end. After B modifies the same content of the same file locally and wants to pull it from the remote warehouse, there will be a merge conflict. , which is the same as the way to resolve conflicts between different local branches.

3.4 Using git in IDEA

I haven’t used idea

4. Basic operation instructions

Created before Except for the .git file, other files in the folder are our working directory. Modify files (add, delete, update) in the working directory. The status of these modifications will change as we execute Git commands
git add: Create a new file from scratch (Not tracked) or modify an existing file (not staged) Use the git add command to save the file to the staging area. (Workspace - Staging area)
git commit: The staging area enters the warehouse and generates a commit record. (Staging area - warehouse) git commit -m "Comment content"
git status: View the status of the working directory and staging area
git log : View the history of commits

  • –all Display all branches
  • –pretty=oneline Display commit information as one line
  • –abbrev-commit Make the output The commit is shorter
  • -graph Display with graph

git reset --hard commitID: Version rollback
You can use git -log or git log command to view the commitID
touch .gitignore Add the file name that you do not want to participate in the update, and you can no longer participate in the warehouse management

Recommended learning: "Git Learning Tutorial

The above is the detailed content of Git tutorial notes organization (summary sharing). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
git
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!