The most concise introduction to Git

 1. Problem solving
   1. Principle of Git;
   2. Common operations of
   Git; 3. Common problems of Git and related operations;
2. Principle of Git
 1. Understanding of four major areas        1.1
       . Work area: the directory where the project is located;
: Temporarily save the file after git add
       1.3. Local warehouse: The place where the modification records of the files are saved locally
       1.4. The remote warehouse: The place where the server saves the modification records of the files      

  2. Conversion between the four major regions

    

         2.1. Command git add <file> to add files from the working area to the staging area;
          2.2. Command git reset head <file> to remove files from the staging area to the working area; 
          2.3. Submit files from the staging area to Local warehouse git commit <file>;
          2.4. Return a changed file from the local warehouse to the temporary storage area (save the modified content) 
               git reset —soft 3dee976bb02fe195d726 (commit ID)
          2.5. Remotely update the code to the local command: git pull
          2.6. Push local code from local to remote git push
   3. Conversion of common process areas (state before operation: just pull down the code from the remote library)      
           3.1. Modify the file, the file is in the working directory at this time, click Version Control under Android studio You can see that modifying the file
           3.2. At this time, it is not possible to use git commit to submit a file. You must first execute git add to put the modified file in the staging area.
           3.3. After placing it in the staging area, execute the git commit command to submit the code to Local repository (right-clicking on the file actually performs two steps)

           3.4. The code is submitted to the local library, the code is modified again, and the modified file is in the workspace state again. It is still necessary to submit it again.

                   git add and then git commit two operations.

           3.5. Execute git push remote code push of local warehouse
3. Common command operations
      1. View status
           1.1. View file modification status: git status
           1.2. View added records: git log
   2. Branch operation
          2.1. View all branches git branch - -all 
          2.2, merge a branch into the current branch git merge dev
          2.3, switch to a local existing branch git checkout dev
          2.4, clone a new branch in the current branch and switch to the new branch git checkout -b dev
   3, commit operation
         3.1 , Locally add to the staging area git add 
         3.2, add the staging area to the local warehouse git commit
         3.3, update the code in the local warehouse git pull
         3.4, push the local code to the remote git push
         3.5, restore to a certain commit (modifications after committing Clear all and use with caution)
              git reset - -hard 3dee975b85a555d726 (commit flag)
         3.6 Restore to a certain commit (all modifications after the commit are returned to the staging area)
          git reset              - -soft 3ded635b85a555d726 (commit flag)           4.        Common
problems and solutions Be a person        2. Save the modified state of the local working directory, switch other branches to do other things (favorite commands)           git stash save the state           git stash pop restore           the most magical command, many times the development is halfway and cannot be submitted. But you can't switch other branches without committing. At this time, this command is very magical        . 3. To avoid conflict expansion,           update the code before pushing the code to the remote, resolve the conflict and submit it, and then push the code








Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324538951&siteId=291194637