Skip to content

Instantly share code, notes, and snippets.

@mindcont
Last active October 6, 2018 01:07
Show Gist options
  • Select an option

  • Save mindcont/fc6a857245a9652749b9c0ebe11ae5fa to your computer and use it in GitHub Desktop.

Select an option

Save mindcont/fc6a857245a9652749b9c0ebe11ae5fa to your computer and use it in GitHub Desktop.
git 常用指令操作

git 常用指令操作

本文针对初级用户,从最简单的讲起,但是需要读者对Git的基本用法有所了解。同时,本文覆盖了上面5个命令的几乎所有的常用用法,所以对于熟练用户也有参考价值。

1 git clone

本地主机生成一个目录,与远程主机的版本库同名

$ git clone https://github.com/torch/distro.git ~/torch --recursive

2 git remote

添加远程仓库地址

$ git remote add yosinski https://github.com/yosinski/caffe.git
$ git fetch --all

git remote show命令加上主机名,可以查看该主机的详细信息。 git remote add命令用于添加远程主机。 git remote rm命令用于删除远程主机。

3 git fetch

一旦远程主机的版本库有了更新(Git术语叫做commit),需要将这些更新取回本地,这时就要用到git fetch命令。

$ git fetch <远程主机名>

取回远程origin主机的master分支

$ git fetch origin master

4 git pull (拉取)

git pull命令的作用是,取回远程主机某个分支的更新,再与本地的指定分支合并。它的完整格式稍稍有点复杂。

$ git pull <远程主机名> <远程分支名>:<本地分支名>

5 git push (推送)

git push命令用于将本地分支的更新,推送到远程主机。它的格式与git pull命令相仿。

$ git push <远程主机名> <本地分支名>:<远程分支名>

6 git submodule

$ git clone https://github.com/mindcont/caffe.git --recursive
$ git checkout deconv-vis
$ git submodule init
$ git submodule update

7 git commit

git filter-branch --commit-filter '
        if [ "$GIT_AUTHOR_EMAIL" = "mindcont@users.noreply.github.com" ];
        then
                GIT_AUTHOR_NAME="mindcont";
                GIT_AUTHOR_EMAIL="mindcont@users.noreply.github.com";
                git commit-tree "$@";
        else
                git commit-tree "$@";
        fi' HEAD




$ git commit --amend --author="mindcont <mindcont@users.noreply.github.com>" -m "更新博客"

参考

Git远程操作详解 2.1 Git 基础 - 取得项目的 Git 仓库

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment