gittest

TOC

Common Commands

    git init     //仓库初始化
    git clone [email protected]/xxxx.git    //克隆远程仓库到本地
    git remote add origin [email protected]/xxxx.git    // 连接到远程仓库
    git status // 查看版本库的状态
    git add .|[file you want add like README.md] // 添加修改的文件进入版本库
    git commit -m "the content of your modify" // 提交版本库
    git push -u origin master // 上传到远程版本库</pre>

git repository configuration global configuration and a single mailbox and username

Global Configuration

git config --global user.name "github's Name"
git config --global user.email "[email protected]"
git config --list

Single warehouse configuration

git config  user.name "github's Name"
git config  user.email "[email protected]"
git config --list

git config --list view the current configuration, the configuration view of the current global configuration + project is below the current configuration of the project, when in use will prefer to use the current configuration of the project


Creating a local ssh-key

ssh-keygen -t -rsa -C "[email protected]"

Then in C: \ the Users \ Administrator.ssh (Windows) directory can see the ssh-key generation.


git from a remote database synchronization to a local warehouse

1. remote repository is changed, there is no change in the local repository

1. See remote repository: Git Remote -v
2. Update the remote to the local repository: Git FETCH Origin Master
3. Comparison of local and remote versions differences: Git log .. Origin Master / Master
4. Merge remote repository: git merge origin / master

2. remote repository does not change local repository changes (local to remote update)

  1. Often see changes: git status
    1. git add .
    2. git commit -m "content"
    3. git push -u origin master

Version rollback: git reset

1. Basic and usage

'' '
1. git version history log //
2. git log --graph // a graphical interface to view historical
3. git reset HEAD ~ n // n roll back to front version, n = previous version
4 . git reset id // id to fall back to any version of a
'' '

2. --hard parameters

Add --hard argument: that modifications fall back to a version of the tune and discard the workspace

git reset --hard HEAD ~ 1 or git reset --hard id

Do not add --hard parameters: This parameter indicates without a fallback version but keep to modify the workspace.

git reset HEAD ~ 1 or git reset id

Push and pull

1 git push: Push to remote local branch

When the modifications are complete, local changes have been submitted to the local library, you can push the local branch of the remote code library.

 git push origin master origin  //表示远程代码库的一个别名(也可以修改为其他名字,可
 git remote                     //master 表示需要推送的分支名称。

If, in the process push prompted the current branch to branch behind schedule remotely, you need to pull the latest state of the remote and local branches by merging git pull command, after the completion of another push to the remote on it.

2 git pull: pull the remote to the local branch and merge

Usually when the local branch behind schedule in remote branch, you need to use this command.

git pull origin master origin   //表示远程代码库的一个别名(也可以修改为其他名字,可
git remote                      //master  表示需要拉取合并的分支名称。

Commonly git pull --rebase origin masterperformed with the rebase manner, no branch merge held clean and tidy

Branch Management

1 git branch: a branch operation

    git branch                //显示本地所有分支以及当前所在哪个分支
    git branch branchName     //用于新建名为 branchName 的新分支
    git branch -d branchName  //用于删除名为 branchName 的分支
    git branch -D branchName  //用于强制删除分支

2 git checkout: switching between branches

In addition to the command to switch between branches functions, can also be used to discard the content of the workspace, there will not be introduced, only the switching between the introduction points

    git checkout branchName     //用于从当前分支切换到名为 branchName 的分支上。
    git checkout -b branchName  //用于新建名为 branchName 的分支并切换到该分支上。

Note the difference between the new branch and git branch, where in addition to the new switching operation also branches

3 git merge: Merge branch

This command is used to merge two branches. Command: git merge branchNameused to branch called branchName merged into the current branch. There are two ways Merge:

  1. fast-forward mode merge: Command:git merge dev

  1. Non-fast-forward mode merge: Command:git merge dev

Note that the difference between two modes: fast-forward mode is only moved HEAD pointer, rather than fast-forward mode is established a new node

Other commands

1 git revert: undo a commit

该命令用于撤销历史上的某次提交,注意该撤销操会作为一个新节点存在于分支上

2 git tag: Operation tag

用于给某次提交打个标签,例如截止到某次提交后完成了某个重大版本的开发,则可以在该次提交打上一个版本的 tag
git tag V1.0   标注V1.0版本

3 git show: Displays information

可用于显示某次提交或者某个 tag 相关的信息。 命令: git show commit_id 显示某次提交的详细信息
命令: git show tag_name 显示某个 tag 的详细信息

4 git blame: View submission history for each line (Responsibility)

git blame file_name

Each line can be used to view a file is created that commit, who submitted, when submitted, the version number is the number of submissions, etc. For more information, easy to go wrong code chase in practical work responsibility, to find those responsible to produce the BUG.

GIT teamwork

In the teamwork process generally have multiple branches, such as a default master branch, there are dev branch for development, as well as test for testing branch for release branch released, and each of the developers of different functions when used feature_xx branch, and so on.

1. Set branch

We often have three branches (master branch, dev branch, test branch) and several feature_xx branch.

  1. master Branches: the main branch, on the line is the final code branch which branch is arranged to be protected (locked), the average developer does not have permission to operate, only the combined team leader has authority;
  2. dev Branch: is a development branch which is set as the default clone branch, is also used for testing prior to the master branch merge, ordinary developers clone from the remote to the local default branch, and other operations may be combined;
  3. test Branch: a branch testers for testing can develop their own modifications branches merged into the test in a test environment for testing branch, the branch is generally not incorporated into any branch;
  4. feature_xx Branches: the user to develop their own functional modules feature branch, you can call feature_login, feature_ui, feature_payment and other development-related function name, function on the development of this branch finished, can be incorporated into the dev branch after the test is correct.

2. The operation of ordinary developer

The average developer, generally follows several steps to develop, test work on it:

  1. Dev clone remote to the local branch, for example: git clone [email protected]:xxx/xxx.git;
  2. Dev pulled out from the branch (new) feature branches for their development, for example: git checkout -b feature_login;
  3. Development work on their feature branch;
  4. Submitted to the development over the current branch with add, commit and other operations;
  5. If you need to be tested in a test environment, then pulled a local branch of a remote test, for example: git branch test origin/test;
  6. Own feature branch into the branch test and test push to a remote branch, such as: git rebase test, git checkout test, git merge feature_login, git push origin test; (Note: We recommend to merge with rebase, to ensure that the branch clean and beautiful)
  7. Through the company's publishing platform will be posted to the remote branch test test environment for testing;
  8. If the test is no problem or do not need to start testing, which can be directly incorporated into the current feature branch dev branch, and push to the remote repository, such as: git rebase dev, git checkout dev, git merge feature_login, git push origin dev; (Note: We recommend using rebase to combine in order to ensure clean branch and beautiful)
  9. In this case indicates that the function has completed the development, code review and release, the team leader needs to be incorporated into the master when the operation; then you can delete your feature branch, for example: git branch -d feature_login;
  10. If the push to the remote when prompted to pull, we recommend using rebase the way: git pull --rebaseto keep the branch clean and beautiful.

3. The team leader of the operation

Because only leader has authority to operate the master branch, so it is necessary to complete the dev branches merged into the master branch, as well as follow-up to play tag and formally launched the offer posted:

  1. Dev to switch to the branch, and pulled up to date, for example: git checkout dev, git pull --rebase origin dev;
  2. After the code review process and the like, to the master branch merge, for example: git rebase master, git checkout master, git merge dev; (Note: We recommend to rebase the combined use, in order to ensure branched clean, beautiful)
  3. Oriented sub-finished version to tag, for example: git tag v1.0 -m "release version 1.0";
  4. The master of the local branch and label after the merger push to a remote repository, for example: git push orgin master --tags.

Guess you like

Origin www.cnblogs.com/DaLinY/p/470fbd84e7d822acf586322ae32da1c4.html