Submit changes to nodeclub for the first time

Source: Internet
Author: User

Today, I submitted two changes to nodeclub for the first time, both of which involve the compatibility of Some browsers. The manager quickly merged my changes so that I can easily get started. In the evening, I went back to work on git's daily operations. I sorted out some git operations and wrote them here. I am happy to be open-source ~ ~

Git beginner's Guide Version rollback
  1. View history

    git logOrgit log --pretty=oneline: List all submission records
    commit 333123123erer123sd123123213123213123
    The submitted ID is next to commit.

  2. Return the corresponding version

    There are two methods to return the version

    First:
    git reset --hard HEAD^: Previous Version
    git reset --hard HEAD^^: Previous Version
    git reset --hard HEAD~66: Last 66 versions

    Second
    git reset --hard commitIDReturns the ID of the corresponding version.
    Commitid can be incomplete, and git will automatically complete

  3. Return to the previous version

    Regret to return to this version.git logOnly information earlier than this version can be viewed
    Okay.git reflogAllows you to view historical operations.

Local repository Management
  1. Add local changes and submit

    The local warehouse is divided into three regions.

    Work ZoneProject catalog
    Temporary Storage AreaStage of the version Library
    BranchMaster and other branches

    After modifying the project in the workspace, you can usegit statusView modified File Information
    Put it in the stage of the temporary storage zone for usegit add somefile.cxs
    Then submit it to the local branchgit commit -m "some message"
    (If you make changes at work but do not add but directly commit, you will be prompted to add the information, but you can also usegit commit -am "some message"Add a parameter.)
    This time modification has been submitted to the local branch

  2. Local temporary storage zone management

    A.Add
    git addCommand to add a file to the temporary storage area. If the file is modified after an add operation, you must add the file again.
    (Git manages modifications. When adding a file, the changes to the current file are not the files themselves.)

    B.View
    git diff HEAD -- somefile.cxsCommand to view the differences between the current workspace file and the version Library

    C.Undo
    # On branch master
    # Your branch is ahead of ‘origin/master‘ by 2 commits.
    # (use "git push" to publish your local commits)
    #
    # Changes to be committed:
    # (use "git reset HEAD <file>..." to unstage)
    #
    # modified: README.md
    # # Changes not staged for commit:
    # (use "git add <file>..." to update what will be committed)
    # (use "git checkout -- <file>..." to discard changes in working directory)
    #
    # modified: README.md
    #
    When we submit changes to the local warehouse, add changes to the temporary storage area, or usegit statusThe above prompt is displayed when you view the status. The above prompt tells us three points

    • There are two commit in the local branch, to be submitted as a remote warehouse, usegit pushSubmit.
    • There is a change in the temporary storage area of the version library. to be submitted to the local repository, usegit reset HEAD fileNameDelete modifications from the temporary storage area
    • A file is modified in the workspace.git add fileNameSubmit to the temporary storage area, usegit checkout -- fileNameRestore the files in the workspace to the last submitted state. The last submission has two statuses. First, if you have used add to submit to the temporary storage area, the status will be restored to the last submitted to the temporary storage area. Second, if the temporary storage space is empty, it will be restored to the State at the last commit.
Remote Repository
  1. Add remote Repository

    Usegit remote add <originName> <gitRepo>Add remote repository address
    Usegit push -u <originName> masterSubmit the latest local modification to the remote repository.

  2. Clone remote repository to local

    Usegit clone <gitRepo>Clone remote repository to local
    (Gitrepo addresses are divided into two types: SSH and HTTPS.)

 

Git collaboration and development Basic branch operations
  1. Create Branch

    git branch devCreate a Dev Branch
    git checkout devSwitch to Dev Branch
    Two steps and one step git checkout -b dev

  2. Branch Switch

    git branchView the current branches
    Find the branch andgit checkout <branchName>Switch
    (Note that branch switching is not allowed when you modify or submit a branch or master branch.)
    Two solutions are available if switchover is not allowed.

    • Solution 1: Delete the changes to the temporary storage area and restore the files modified in the workspace to the level before modification. The two commands involved here have already been discussed,git reset HEAD fileNameAndgit checkout -- fileName
    • Solution 2: Usegit stashThe command saves the current work, which is equivalent to protecting the site.
      Usegit stash listTo view the stored work, usegit stash popYou can also usegit stash apply <stashName like [email protected]{0}>Reply to a job
  3. Merge Branch

    The operations on Dev and other branches are the same as those on the master.git checkout masterSwitch to the master branch and merge the branches. There are two ways to merge the branches.

    • Method 1: Usegit merge <branchName>If you use this method to merge and delete a branch, the branch information will be lost.
    • Method 2:(Recommended) git merge --no-ff -m "some message" <branchName>

    The difference between the two methods is as follows:

    Method 1:

    Method 2:

  4. Conflict resolution during merge

    When we merge branches, this prompt will appear if there is a code conflict.
    Auto-merging somefile.cxs
    CONFLICT (content): Merge conflict in somefile.cxs
    Automatic merge failed; fix conflicts and then commit the result
    This indicates that there is a code conflict in the somefile. cxs file. The conflict is identified as follows.
    <<<<<<< HEAD
    Creating in Master.
    =======
    Creating in dev.
    >>>>>>> dev
    Modify the code beforegit add somefile.cxs
    Thengit commit -m "fixed somefile.cxs conflict"Submit

  5. View Project branches and delete branches

    git log --graph --pretty=oneline --abbrev-commitCommand to display the branch status of the project in a graphical manner.
    git branch -d <branchName>You can delete a branch. Sometimes it is required that the branch has not been merged into the master.git branch -D <branchName>Command to delete Branch

  6. Multi-person collaboration mode

    The steps for multi-person collaboration are as follows:

    • Usegit push origin <branchName>If an error occurs, the code of the remote branch conflicts with you.

    • If the code conflicts, usegit pull originCapture remote warehouse merging. If you want to insure yourself, you can firstgit fetch origin master:tmpThengit diff master tmpCheck the differences between the remote repository and your code. Thengit merge tmpResolve the code conflict, submit it to the local repository, and then push it to the remote repository.

    • If you develop a branch of the remote repository, you need to create a branch locally. The command is as follows:git checkout -b dev origin/dev
      (When cloning, you can only see the master branch, but not the other branches.)
      Then usegit branch --set-upstream <branchName> origin/<branchName>Associate the local branch with the remote warehouse branch, and then perform the two steps mentioned above

 

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.