Git是什么? Git是目前世界上最先进的分布式版本控制系统(没有之一)。 Git有什么特点?简单来说就是:高端大气上档次!
上面是国内某牛人的git介绍。想详细了解git的同学可以访问一下的网址,花几分钟的时间学习一下世界上最先进的分布式版本控制系统!
git rm – 删除文件
删除本地文件,并更新到远程仓库中
0. 删除本地文件 1. git status -s // 查看有更改的文件 2. $ git rm interView/javaScript/text.txt // 在本地仓库中删除更改手动删除的文件 3. $git commit -m "chore: 删除多余的文件" 4. $git push origin master // 提交这样就将本地删除的文件同步到远程仓库中了。
你的本地仓库由 git 维护的三棵“树”组成。第一个是你的* 工作目录,它持有实际文件;第二个是 暂存区(Index),它像个缓存区域,临时保存你的改动;最后是 HEAD*,它指向你最后一次提交的结果。
你可以提出更改(把它们添加到暂存区),使用如下命令:
git add <filename> git add *这是 git 基本工作流程的第一步;使用如下命令以实际提交改动:
git commit -m "代码提交信息"现在,你的改动已经提交到了 HEAD,但是还没到你的远端仓库。
你的改动现在已经在本地仓库的 HEAD 中了。执行如下命令以将这些改动提交到远端仓库:
git push origin master可以把 master 换成你想要推送的任何分支。
如果你还没有克隆现有仓库,并欲将你的仓库连接到某个远程服务器,你可以使用如下命令添加:
git remote add origin <server>如此你就能够将你的改动推送到所添加的服务器上去了。
上面的命令git remote add <name> <url>可以将你的本地仓库连接到某个远程服务器。同样的的,一个项目也可以连接到多个远程服务器。其中name也就是这个远程仓库的名称,url是这个远程仓库的URL地址。例如
git remote add outOrigin https://github.com/springHyc/InterviewLibrary.git可以使用git remote -v来查看该项目的远程仓库的连接情况。eg:
ehe:InterviewLibrary hehe$ git remote -v origin https://github.com/springHyc/InterviewLibrary.git (fetch) origin https://github.com/springHyc/InterviewLibrary.git (push)同样的可以使用命令git remote remove <name>删除一个连接的远程仓库地址。
查看更多有关remote的命令,可以使用git remote --h来进行查看。
hehe:InterviewLibrary hehe$ git remote -h usage: git remote [-v | --verbose] or: git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url> or: git remote rename <old> <new> or: git remote remove <name> or: git remote set-head <name> (-a | --auto | -d | --delete | <branch>) or: git remote [-v | --verbose] show [-n] <name> or: git remote prune [-n | --dry-run] <name> or: git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...] or: git remote set-branches [--add] <name> <branch>... or: git remote get-url [--push] [--all] <name> or: git remote set-url [--push] <name> <newurl> [<oldurl>] or: git remote set-url --add <name> <newurl> or: git remote set-url --delete <name> <url> -v, --verbose be verbose; must be placed before a subcommand用户名和邮箱地址是本地Git客户端的一个变量,不随git库而改变。每次commit都会用用户名和邮箱纪录。github的contributions统计就是按邮箱来统计的。
查看用户名和邮箱地址 $ git config user.name $ git config user.email 修改用户名和邮箱地址 $ git config --global user.name "username" $ git config --global user.email "email" 查看git配置 $ git config --list各个配置项的含义
hehe:InterviewLibrary hehe$ git config --list // 查看命令 core.trustctime=false credential.helper=osxkeychain user.name=贺贺 user.emai=hyc***@sinosoft.com.cn user.email=zhulinger520@163.com filter.lfs.smudge=git-lfs smudge %f filter.lfs.required=true filter.lfs.clean=git-lfs clean %f core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true core.ignorecase=true core.precomposeunicode=true remote.origin.url=https://github.com/springHyc/InterviewLibrary.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/masterGitHub上下载的项目,尤其是团队共享的项目很可能每次提交时都需要输入账号密码,很是麻烦。可以使用一下命令来解决这个麻烦。
在输入完账号密码后,可以执行下面的命令来记住密码。
设置记住密码(默认15分钟): git config --global credential.helper cache如果想自己设置时间,可以这样做: git config credential.helper 'cache --timeout=3600' 这样就设置一个小时之后失效长期存储密码: git config --global credential.helper store