Common git operation commands and git operation commands

Source: Internet
Author: User
Tags using git

Common git operation commands and git operation commands

Record the common Git command operations in the work. A project is often developed by multiple people in collaboration. Using git is a required skill for developers. Below are some basic git operations recorded, in the future, we will record git conflicts, merge branches, roll back, and tag operations.

Clone project-git clone:
git clone https://test.git
After the project is cloned, if you want to switch to the specified branch, run the following command:
Git branch-a # view the branches of the Project git checkout dev-test # Switch to the dev-test branch git branch # There is a branch name before *, which indicates the current branch
Check which files have been modified-git status
git status 
Follow these steps to submit code: add the file to be submitted-git add:
Git add a.txt then add a.txt to git trace git add xxx/testdemo/B .txt # When adding a file under the project root directory, you need to write the absolute path of the file git add. # If you need to add all files, you can use. indicates all modified files in the current directory.
Modify the file submitted by the "Clear add" command to the temporary storage area-git reset HEAD

(This means that README has been added. after the md is added to the local repository, the status of the git status check file has changed to green. In this case, the file add is incorrect. To recall the File status, see the red box for operation commands)

Git reset head readme. md # Clear the README Statement submitted by the add command to the temporary storage area. modify the md file, that is, the file has not changed git status # view the file changes again and change it to modified again
Submit the modification to the local repository-git commit-m 'xxxx'
Git commit-m 'cmda.txt file' # submit the file to the local repository and carry the demessage information submitted this time
Push to a remote repository in the following common scenarios: 1. Submit the code normally-git push origin branch
Git push origin master # push to the master branch of the remote warehouse. origin: indicates the address of the remote warehouse, and master: indicates the branch number.
2. Two people modify the same file at the same time, and then perform the push operation after commit.

(A modified the README. md file and submitted it successfully. B also modified the README. md file and then performed the push operation.) the error message is as follows:

Git push origin master # code added to the local repository and pushed to the remote Repository

 

Refuse to obtain code from the master group for the first time. The solution is to pull the latest code from the git remote repository-git pull

(Two people modify the same file at the same time. If a has successfully submitted the code first, B will encounter this problem when pushing the code again, because the modified Code of B is not modified on the basis of the modified Code of a, but is changed using the old code, the push code may conflict)

To resolve a file conflict, follow these steps:

1. Pull the latest code. The command is as follows (Conflict occurs. The Code branch is changed to master | MERGING.):

Git pull origin master # pull the latest code again. origin: indicates the address of the remote repository, and master: indicates the branch number of the Code.

When pulling the latest code from the git remote repository, the code is automatically merged with the local code. The README. md file conflicts occur: conflicts occur when the code is merged. You need to resolve the conflicts first and then commit again.

2. Edit conflicting files and delete incorrect changes

The red lines of the table distinguish code conflicts. They are separated by ======. The above is the initial modification, and the following is the latest modification, delete the changes that do not need to be retained and save the changes.

3. After resolving the conflict, You need to git add xx file to the local repository.

 

Git add README. md # add the file to the local repository after resolving the conflict

4. Submit git commit to the local repository again. The commit log information is displayed. q! Exit.

Git commit # after resolving file conflicts, submit git commit directly to the local repository.

5. finally push to the remote warehouse

Git push origin msater # push to remote Repository
Pull the latest code
Git pull origin master # pull the latest code from the remote repository to the local device. origin: indicates the address of the remote repository, and master: indicates the branch number.
View the submission history. You can see the submitted submitter, submission time, and message.
git log 

Subsequent supplements ~~~~~~~~~~~~

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.