http://rogerdudler.github.io/git-guide/index.zh.html https://www.shiyanlou.com/questions/2669
几个专用名词的译名如下。
Workspace:工作区Index / Stage:暂存区Repository:仓库区(或本地仓库)Remote:远程仓库
在Linux上安装Git
首先,你可以试着输入git,看看系统有没有安装Git:
$ git
The program
'git' is currently
not installed. You can install
it by typing:
sudo apt-
get install git
像上面的命令,表示Git没有安装。
如果你碰巧用Debian或Ubuntu Linux,通过一条sudo apt-get install git就可以直接完成Git的安装,非常简单。
如果是其他Linux版本,可以直接通过源码安装。先从Git官网下载源码,然后解压,依次输入:./config,make,sudo make install这几个命令安装就好了。
配置
Git的设置文件为.gitconfig,它可以在用户主目录下(全局配置),也可以在项目目录下(项目配置)。
$ git config --list
$ git config -e [--global]
$ git config [--global] user.name
"[name]"
$ git config [--global] user.email
"[email address]"
因为Git是分布式版本控制系统,所以,每个机器都必须自报家门:你的名字和Email地址。
新建版本库
首先,选择一个合适的地方,创建一个空目录:
$ mkdir learngit
$ cd learngit
第二步,通过git init命令把这个目录变成Git可以管理的仓库:
$ git init
$ git init [project-name]
$ git clone [url]
增加/删除文件
$ git add [file1] [file2]
...
$ git add [dir]
$ git add .
$ git rm [file1] [file2]
...
$ git rm --cached [file]
$ git mv [file-original] [file-renamed]
代码提交
$ git commit -m
"message"
$ git commit [file1] [file2]
... -m
"message"
$ git commit -a
$ git commit -v
$ git commit --amend -m
"message"
$ git commit --amend [file1] [file2]
...
一旦提交后,如果你又没有对工作区做任何修改,那么工作区就是“干净”的
分支
$ git branch
$ git branch -r
$ git branch -a
$ git branch [new-branch]
$ git checkout -b [branch]
$ git branch --track [branch] [remote-branch]
$ git checkout [branc]
$ git merge [branch]
$ git branch -d [branch]
标签
$ git tag
$ git tag [tag]
$ git tag [tag] [commit]
$ git show [tag]
$ git push [remote] [tag]
$ git push [remote] --tags
查看信息
$ git status
$ git log
$ git log --stat
$ git log --follow [file]
$ git whatchanged [file]
$ git log -p [file]
$ git blame [file]
$ git diff
$ git diff --cached [file]
$ git diff
HEAD
$ git show [commit]
$ git show --name-only [commit]
$ git show [commit]
:[filename]
$ git reflog
远程同步
$ git remote -v
$ git remote show [remote]
$ git remote add [shortname] [url]
$ git remote rm [shortname]
$ git fetch [remote]
$ git pull [remote] [branch]
$ git push [remote] [branch]
$ git push [remote] --force
$ git push [remote] --all
撤销
$ git checkout [file]
$ git checkout [commit] [file]
$ git checkout .
$ git reset [file]
$ git reset --hard
$ git reset [commit]
$ git reset --hard [commit]
$ git reset --keep [commit]
$ git revert [commit]
其他
$ git archive
转载请注明原文地址: https://ju.6miu.com/read-1124502.html