Git 指令收集

git命令介绍

  • git简单命令

git init该命令用来安装Git追溯项目更改历史的所有工具。

git add filename

git status

git log

git commit -m "comments"

git checkout HEAD filename: Discards changes in the working directory. (从repositorycheckout覆盖当前工作目录的内容)

git reset HEAD filename: Unstages file changes in the staging area.(reset 'git add '之后的内容)

git reset SHA: Can be used to reset to a previous commit in your commit history.(reset到上一次commit, SHA表示SHA码的前7位)


git branch介绍

        git默认只在masterbranch工作,如果想要在其他的版本上做些实验性的功能开发可以用到多个branch.

git branch: 显示所有的branch, 最初只有 master

Git 指令收集

创建一个新的branch : git branch new_branch

刚创建出来的新branch 跟master是一样的,他们是共享同样的commit历史。可以用如下命令切换branch:

git checkout new_branch

 将两个branch 的commit代码合并:

git merge branch_name

 例如将new_branch的代码merge到master的步骤:

        1. 切换到master : git checkout master

        2. merge branch: git merge new_branch

branch任务开发完成merge到mater之后就可以关闭new_branch了

git branch -d new_branch


git团队协作

clone远程的repository:

git clone remote_location clone_name  

在这个命令中:

remote_location 告诉 Git 去找找到 remote. 它可以是一个web地址,或者是一个文件路径:/Users/teachers/Documents/some-remote

clone_name 是指定Git clone repository放置的路径名

The workflow for Git collaborations typically follows this order:

1.Fetch and merge changes from the remote (git clone ; git merge)

2.Create a branch to work on a new project feature (git branch)

3.Develop the feature on your branch and commit your work

4.Fetch and merge from the remote again (in case new commits were made while you were working) (git fetch; git merge)

5.Push your branch up to the remote for review (git push)


git clone: Creates a local copy of a remote.

git remote -v: Lists a Git project's remotes.

git fetch: Fetches work from the remote into the local copy.

git merge origin/master: Merges origin/master into your local branch.

git push origin <branch_name>: Pushes a local branch to the originremote.



转载于:https://my.oschina.net/athhu/blog/534145