Summary of some basic commands of git

Git is the most advanced distributed version control system in the world

For the usage of git, this article does not belong to a tutorial, it just summarizes and records some simple commands that are usually used

git download address: https://git-scm.com/downloads

The main summary is as follows:

1. Version creation

2. Undo changes

3. Version rollback

4. Submit the remote repository

5. Branch management

 

1. Version creation

 (1.1) Initialize a git repository

    1. Use git init

 (1.2)  Add files to the git repository, in two steps

    (1.2.1)  git add <file> //git add . (. represents all files)
    (1.2.2)   git comit -m 'Commit description

 

  (1.3) View warehouse status

    1.git status

    2. git diff : View the specific modifications of the version that has not been submitted to the repository

 

2. Undo changes

  (2.1)  Command  git checkout -- file.txt

      This means that all modifications to the readme.txt file in the workspace are undone. There are two situations:

      1. One is that readme.txt has not been placed in the temporary storage area since it was modified. Now, undo the modification and return to the same state as the version library;

      2. One is that after readme.txt has been added to the temporary storage area, it has been modified. Now, undo the modification and return to the state after adding it to the temporary storage area.

   (2.2) Command git reset HEAD file

 

          The git reset command can either roll back the version or roll back the changes in the staging area to the workspace. When we use HEAD, it means the latest version.

 

3. Version rollback

  (3.1) View version history (one version per commit)

      1. git log      (details)
      2. git log --pretty=oneline (simplified)


    (3.2) Version fallback

    (3.2.1), git reset --hard HEAD^    back to the previous version
    (3.2.2), git reflog   to view the command history, and determine the future version
    (3.2.3), git reset --hard commit_id    commit_id go back to the specified version

      Description: In git, HEAD represents the current version, HEAD^ is the previous version, HEAD^^ is the previous version,

    Git allows us to traverse the history of versions using the command git reset --hard commit_id

 

4. Remote warehouse

    (4.1), establish association between local and remote git warehouse

      git remote add origin remote warehouse address

   (4.2), if the establishment reports an error: delete the establishment

      git remote rm origin

   (4.3), submit to remote git push -u origin master (the first submission takes parameter -u)
      

   (4.4)、如果提交出现以下错误:
      ! [rejected] master -> master (fetch first)
      error: failed to push some refs to ‘远程仓库地址’

      解决:合拼:【注:pull=fetch+merge】
      命令:git pull --rebase origin master

   (4.5)  克隆远程项目到本地

      git clone 远程仓库地址

   (4.6)  获取最新版本  有两种  拉取 和 获取 pull 和 fetch

      (4.6.1)、git  pull     将远程存储库中的更改合并(merge)到当前分支中            git pull origin master

      (4.6.2)、git  fetch   从远程获取最新版本 到本地   不会自动合并( merge)     git fetch  origin master    

      实际运用中一般推荐第二种 : git fetch 

5.分支管理

   (5.1)、查看分支:git branch

   (5.2)、创建分支:git branch <name>

   (5.3)、切换分支:git checkout <name>

   (5.4)、创建+切换分支:git checkout -b <name>

   (5.5)、合并某分支到当前分支:git merge <name>

   (5.6)、删除分支:git branch -d <name>

 

参考推荐学习:

    廖雪峰git教程:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

    易百教程:https://www.yiibai.com/git/

完结。。。谢谢

 

Guess you like

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