美文网首页
git 相关

git 相关

作者: James_Geng | 来源:发表于2017-05-22 19:03 被阅读20次

    1,git clone ..  克隆远程分支到本地。

    2,git checkout branchName 在本地切换分支  

          git checkout -b branchName  // create and checkout a new branch

          git check out -t branchName // --trackset upstream info for new branch

          git checkout -h // 查看git checkout 帮助

    3,git commit 提交本地改动

          git commit -m'some change' // 提交本地改动到本地仓库

          git commit -a // 提交本地全部改动到本地(需谨慎操作)

    4,git push origin developer 推送本地仓库改动到远程仓库

          git push origin branchName // 该远程分支创建

          git push origin -u branchName // 该远程分支未创建时使用

    5,git merge 合并分支

         git fetch origin developer // 从远程的origin仓库的developer主分支更新最新的版本到当前分支上

         git log -p branchName..origin/developer // 比较本地的branchName分支和origin/developer分支的差别

         git merge origin/developer // 合并内容到本地当前分支

         git pull // 相当于git fetch 和 git merge,即更新远程仓库的代码到本地仓库,然后将内容合并到当前分支。

    6,常见操作

          git add 添加文件

          git add . 添加所有文件

          git stash //把本次自己的代码改动暂存起来

          git pull origin Developer //拉取远程最新的代码到本地,(相当于git fetch 和 git merge)

          git stash pop //恢复第一步暂存的代码,这时候如果代码中有冲突需手动解决

          git rm --cache '文件名' // 有时不想删除本地的文件, 只是想让git不再track, 这时可以使用 git rm --cached 文件路径

    7,Github 上怎样把新 commits 使用在自己的 fork 上:

          1、配置上游项目地址。即将你 fork 的项目的地址给配置到自己的项目上。比如我 fork 了一个项目,原项目是 wabish/fork-demo.git,我的项目就是 cobish/fork-demo.git。使用以下命令来配置。

         ➜ git remote add upstream https://github.com/wabish/fork-demo.git

          然后可以查看一下配置状况,很好,上游项目的地址已经被加进来了。

         ➜ git remote -vorigin  git@github.com:cobish/fork-demo.git(fetch)origin  git@github.com:cobish/fork-demo.git(push)upstream    https://github.com/wabish/fork-demo.git(fetch)upstream    https://github.com/wabish/fork-demo.git(push)

          2、获取上游项目更新。使用 fetch 命令更新,fetch 后会被存储在一个本地分支 upstream/master 上。

          ➜ git fetch upstream

          3、合并到本地分支。切换到 master 分支,合并 upstream/master 分支。

          ➜ git merge upstream/master

          4、从远程仓库同步到 自己fork后的仓库 (同步分支等)

          ➜ git remote update

    链接:https://www.zhihu.com/question/20393785/answer/105370502

    参考资料:http://www.zhanglian2010.cn/2014/07/git-pull-vs-fetch-and-merge/
                      https://www.oschina.net/translate/git-fetch-and-merge?cmp&p=1#

                      http://www.jianshu.com/p/ae4857d2f868 // 如何从从detached HEAD状态解救出来

    相关文章

      网友评论

          本文标题:git 相关

          本文链接:https://www.haomeiwen.com/subject/dcdixxtx.html