Learning and using Git tools

 

 

1. Work area and staging area


The first step is to use git add to add the file, which is actually to add the file modification to the staging area.

The second step is to commit the changes with git commit, which actually commits all the contents of the staging area to the current branch.

The third step is to use git push to submit the code of the local warehouse to the remote warehouse.

 

 

 

2. The difference between fetch and pull

 

       git fetch origin will fetch all updates uploaded to this remote repository since your last clone (or updates submitted by others since the last fetch). It is important to remember that the fetch command only pulls the remote data to the local repository, and does not automatically merge into the current working branch. Only when you are really ready, you can manually merge.

 

        If a branch is set to track a branch of a remote warehouse (see the next section and Chapter 3), you can use the git pull command to automatically grab the data, and then automatically merge the remote branch into the local warehouse current branch. We use this a lot in our day-to-day work, it's fast and good. In fact, by default the git clone command essentially automatically creates a local master branch for tracking the master branch in the remote repository (assuming the remote repository does have a master branch). So generally we run git pull, the purpose is to grab the data from the original cloned remote warehouse and merge it into the current branch in the working directory.

 

   3. The role of the temporary storage area stage

      1. git history, there is no visual tool on the linux command line, it is difficult to find all the files for git commit, so linus adds the stage area of ​​git add.

     2. If we develop a new function without sufficient self-testing, and we cannot submit the remote warehouse for the time being, we can add it to the git stage. Continue to do some test development. If you want to go back to the previous submission at this time, you can restore it from the stage at this time.

 

 

   4. About the development mode of Git Fork

       1) Fork from another project to make it your own project code

       2) When submitting, submit it to your own git address first, and then pass the merge request on the git interface to the author's project, but the real merge is done by the author.

       3)如何让自己的项目与作者的最新代码保持一致

             git remote -v    查看自己的远程仓库

             git remote add pb git://github.com/paulboone/ticgit.git  添加远程仓库

             git remote -v    查看自己的远程仓库

             git pull pb dev  合并远程仓库的最新代码,后面两个参数一个是仓库名 还有一个是分支的名称   

             或者先git fetch pb 到本地, git checkout dev , git merge pb/dev

 

   5. git 提交到远程仓库,想回滚怎么办?

       git revert 相应的提交(这一步只是回滚本地提交)

       git commit and push 

 

   6. git 新建本地分支来跟踪远程分支

       git checkout -b local_branch origin/remote_branch

 

  7.  git 项目迁移

       比如你原来的是http://xxA.git master,要迁移到http://xxB.git dev怎么搞呢?

       git clone http://xxB.git

       git checkout -b dev origin/dev

       git remote add  arepo http://xxA.git master // 添加A仓库为远程仓库

       git pull arepo master   //合并A仓库的master分支代码

       git push                       // 提交到B仓库

 

 8. 关于git stash

     git stash save "save message"

     git stash list

     git stash pop stash@{num}

     git stash drop stash@{num}

     git stash clear

   

 9. 基于当前master分支的某个版本拉分支

    当前在master

    git checkout -b hotfix_xxx d814a27f557ce19da12eb93e2634c03c3c79f6de

    git push origin hotfix_xxx

 

 

             

 

 

 

       

Guess you like

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