git 安装
windows
推荐使用 git-bash 下载地址
如果在windows自带的cmd命令行中运行git命令出现'git'不是内部或外部命令
在环境变量path中添加git安装目录下的cmd目录的路径。在安装git时,使用什么样的命令行工具,不要选择第一个只从git bash中使用git,就会自动在path中添加如下环境变量。
C:\Program Files\Git\cmd
Debian/Ubuntu
sudo apt-get install git
其它 linux 版本
官方文档:https://git-scm.com/download/linux
查看 git 版本
git --version
git 配置
git config --global user.name "your name"
git config --global user.email "your email"
配置完成后,需要创建验证用的公钥
/* ubuntu下先安装一下ssh */
sudo apt-get install ssh
/* 用户目录~/.ssh/下建立相应的密钥文件 */
ssh-keygen -t rsa -C 'you email address@gmail.com'
常用 git 命令
cd <destDir/>
git init
/*添加所有文件*/
git add .
git commit -m 'first commit'
git remote add origin <server>
git pull origin master
git push origin master
---------------------
/* 错误提示 */
git pull
git branch --set-upstream-to=origin/master
//git pull --allow-unrelated-histories
git add .
git commit -m 'first commit'
git push
--------------------
git status
git diff
git log
git checkout ..可以回退到某个版本
----------------------
git clone <server>
cnpm install
ng serve --prod
ng build --prod
更新项目
git pull
cnpm update
ng serve
----------------------
多人协作
git branch
查看当前分支
git checkout -b dev
创建dev分支
git branch -m oldname newname
重命名本地分支
git branch
vi a.js
git status
git diff
查看修改了哪些地方
git push origin dev
git checkout master
git pull origin master
git merge dev
git push origin master
修改最后一次提交
git commit --amend
取消已暂存的文件
/* 两个文件需要单独提交,一不小心 git add . */
git add .
/* git status 查看状态,命令输出会有所提示 */
git status
/* 取消暂存 */
git reset HEAD <file>...
git status
取消对文件的修改
/* 觉得刚才对 xxxx.txt 修改完全没有必要,取消修改,回到之前的状态 */
$ git status
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: xxxx.txt
#
//这条命令很危险,请务必确认真的不再需要保留刚才的修改
$ git checkout -- xxxx.txt
$ git status
查看当前的远程库
git remote
/*也可以加上 -v 选项(译注:此为 --verbose 的简写,取首字母),显示对应的克隆地址:*/
git remote -v
添加远程库
/* 添加新的远程库,指定一个简单的名字以便引用 */
git remote add [shortname] [url]
从远程仓库抓取数据
/*抓取上次 fetch 以来别人提交的更新,并不会合并到当前工作分支*/
git fetch [remote-name]
/* 自动抓取数据,将远端分支自动合并到本地仓库当前分支 */
git pull
推送数据到远程仓库
git push [remote-name] [branch-name]
查看远程仓库信息
/* 查看某个远程仓库的详细信息 */
git remote show [remote-name]
远程仓库的删除和重命名
git remote rename
$ git remote rename pb pdd
$ git remote
origin
pdd
/* 移除对应的远端仓库,可以运行 git remote rm */
$ git remote rm pdd
$ git remote
origin
Git 命令别名
$ git config --global alias.unstage 'reset HEAD --'
/* 下面两条命令等价 */
$ git unstage <filename>
$ git reset HEAD <filename>
/* 查看最后一次提交的信息 */
git config --global alias.last 'log -1 HEAD'
git分支改名
如果分支不是当前分支
git branch -m 原名 新名
如果分支是当前分支
git branch -m 新名
删除本地和远程分支
git branch -a
查看所有分支包括远程分支
git branch -d branch-name
删除本地分支
git push origin --delete branch-name
删除远程分支
合并分支
git merge [branch_name1] 将branch_name1分支合并到当前分支。
撤销上一次的合并分支:git merge --abort
.gitignore 模板(仅供参考)
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
/out-tsc
# dependencies
node_modules/
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
testem.log
/typings
# e2e
/e2e/*.js
/e2e/*.map
# System Files
.DS_Store
Thumbs.db







网友评论