参考阅读:
workspace
—— 本地工作目录index
—— 暂存区local
—— 本地仓库,HEAD,指向最后一次提交的结果remote
—— 远程仓库
git config --global user.name "name"
—— 配置全局 Git 用户名git config --global user.email "[email protected]"
—— 配置全局 Git 邮箱git config user.name "name"
—— 配置当前仓库 Git 用户名git config user.email "[email protected]"
—— 配置当前仓库 Git 邮箱git config --global user.name
—— 查看全局 Git 用户名git config --global user.email
—— 查看全局 Git 邮箱git config user.name
—— 查看当前仓库 Git 用户名git config user.email
—— 查看当前仓库 Git 邮箱
git init
—— 仓库初始化git clone [url]
—— 获取远程仓库到本地git remote add [remote-name] [remote-url]
—— 添加一个新的远程仓库git remote
—— 列出所有的 remotegit remote -v
—— 列出所有的 remote 的地址git remote rm [remote-name]
—— 删除一个 remotegit reomte rename [old-name] [new-name]
—— 重命名 remote
git add [file]
—— 添加修改文件,workspace -> indexgit add .
—— t添加所有修改文件,workspace -> indexgit commit -m "提交信息"
—— 文件提交,index -> localgit commit --amend
—— 与上次 commit 合并,index -> localgit push [remote-name] [loca-branch]:[remote-branch]
—— 把本地的某个分支推送到远程仓库的某个分支,local -> remotegit fetch
—— 抓取远程仓库至最新改动git merge [branch]
—— 合并其他分支到当前分支git pull [reomte] [branch]
—— 更新本地仓库到最新改动,remote -> workspacegit status
—— 查看修改状态git log
—— 查看提交记录git show
—— 展示提交的内容git stash
—— 暂存修改git stash pop
—— 弹出之前暂存的修改
git checkout -b [branch-name]
—— 创建分支,并切换到该分支git checkout [branch-name]
—— 切换到该分支git branch [branch-name]
—— 创建分支git branch -d [branch-name]
—— 删除分支git branch -m [old-name] [new-name]
—— 重命名分支git branch
—— 查看所有分支git branch -a
—— 查看远程所有分支
git reset --hard HEAD~
—— 撤销提交,local -> workspace,修改的文件也会丢失git reset --soft HEAD~
—— 撤销提交,local -> indexgit reset --mixed HEAD~
—— (默认)撤销提交,local -> workspace,修改的不会会丢失git checkout [filename]
—— index -> workspace,修改丢失git rm [filename]
—— 从版本库中移除,删除源文件git rm [filename] --cached
—— 从版本库中移除,不删除源文件git rm -r [folder-name]
—— 从版本库中移除,删除源文件
git diff
—— 对比 workspace 和 indexgit diff HEAD
—— 独臂 workspace 与最后一次提交git diff [source-branch] [target-branch]
—— 对比两个分支差异git add [filename]
—— 冲突修改完,需 add 标记合并成功
在本地仓库根目录创建 .gitignore 文件。Win7 下不能直接创建,可以创建 ".gitignore." 文件,后面的标点自动被忽略;
/.idea
—— 过滤指定文件夹/fd/*
—— 忽略根目录下的 /fd/ 目录的全部内容;*.iml
—— 过滤指定的所有文件!.gitignore
—— 不忽略该文件