Git 当下最流行的版本管理工具,结合自己工作中的实际应用做了以下梳理,如果您在使用中还有其它问题欢迎评论留言
git init 初始化本地仓库git add-A. 来一次添加所有改变的文件git add-A 表示添加所有内容git add. 表示添加新文件和编辑过的文件不包括删除的文件git add-u 表示添加编辑或者删除的文件,不包括新添加的文件git commit-m'版本信息' 提交的版本信息描述git status 查看状态git push-u origin master 推送到远程仓库看git pull 拉取远程仓库代码到本地git branch-av 查看每个分支的最新提交记录git branch-vv 查看每个分支属于哪个远程仓库git reset--hard a3f40baadd5fea57b1b40f23f9a54a644eebd52e 代码回归到某个提交记录git branch-agit branch devgit branchgit checkout devgit branch-d devgit push origin:devgit remote rm origin 先删除git remote add origin仓库地址 链接到到远程git仓库git remoteset-url origin仓库地址git pull命令git fetch origin mastergit log-p master..origin/mastergit merge origin/mastergit remote add origin git@github.com:XXXX/nothing2.gitgit checkout-b dev origin/devfatal: Cannot update paths and switch to branch 'dev' at the same time.Did you intend to checkout 'origin/dev' which can not be resolved as commit?git branch-a 命令来查看本地是否具有dev分支
git fetch origin dev 命令来把远程分支拉到本地git checkout-b dev origin/dev 在本地创建分支dev并切换到该分支
git pull origin dev 就可以把某个分支上的内容都拉取到本地了http://www.scootersoftware.com/download.php
https://git-scm.com/book/zh/v2
如何解决 failed to push some refs to git
git pull--rebase origin master 进行代码合并git push-u origin master 即可完成代码上传If you wish to set tracking information for this branch you can do so with:git branch --set-upstream-to=origin/<branch> master指定当前当前工作目录工作分支,跟远程仓库分支之间的联系
git branch --set-upstream master origin/master获取 git pull 最新代码报以下错误:
fatal: refusing to merge unrelated historiesgit pull之后加上可选参数 --allow-unrelated-histories 强制合并
git pull origin master --allow-unrelated-histories使用钩子 pre-commit,提交代码提示如下错误:
$ git commit -m '.'sh: eslint: command not foundpre-commit:pre-commit: We've failed to pass the specified git pre-commit hooks as the `fix`pre-commit: hook returned an exit code (1). If you're feeling adventurous you canpre-commit: skip the git pre-commit hooks by adding the following flags to your commit:pre-commit:pre-commit: git commit -n (or --no-verify)pre-commit:pre-commit: This is ill-advised since the commit is broken.pre-commit:.git/hooks 文件夹,找到 pre-commit.sample 文件,将以下代码替换到文件中,或者, npm install pre-commit--save 也可以,这个命令会自动执行以下操作。#!/bin/bashTSLINT="$(git rev-parse --show-toplevel)/node_modules/.bin/tslint"for file in $(git diff --cached --name-only | grep -E '\.ts$')do git show ":$file" | "$TSLINT" "$file" if [ $? -ne 0 ]; then exit 1 fidonepre-commit.sample文件名修改为 pre-commit。.gitignore 规则不生效的解决办法
把某些目录或文件加入忽略规则,按照上述方法定义后发现并未生效,原因是.gitignore只能忽略那些原来没有被追踪的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。那么解决方法就是先把本地缓存删除(改变成未被追踪状态),然后再提交:
git rm -r --cached . 或者 git rm -r README.mdgit add .git commit -m 'update .gitignore'作者推荐