git相关
<h2>安装</h2>
<p>下载:<a href="https://git-scm.com/downloads">https://git-scm.com/downloads</a></p>
<p>配置用户:</p>
<pre><code>$ git config --global user.name &quot;Your Name&quot;
$ git config --global user.email &quot;email@example.com&quot;</code></pre>
<h2>基础知识</h2>
<p>在Git中,用HEAD表示当前版本,上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。</p>
<p>.git/index 或 stage 是暂存区,<code>git add</code> 就是将文件修改添加到暂存区。-- todo 手动验证看看</p>
<p><code>git reflog</code> 用来记录你的每一次命令:</p>
<p><code>git add</code> 是将文件添加到暂存区。</p>
<pre><code>git commit -m [message] 提交暂存区到仓库区,message为说明信息
git commit [file1] -m [message] 提交暂存区的指定文件到本地仓库
git commit --amend -m [message] 使用一次新的commit,替代上一次提交</code></pre>
<pre><code>git log 查看提交历史
git log --oneline 以精简模式显示查看提交历史
git log -p &lt;file&gt; 查看指定文件的提交历史
git blame &lt;file&gt; 一列表方式查看指定文件的提交历史</code></pre>
<p>有些伙伴可能对使用git pull还是git fetch有点疑惑,其实 git pull = git fetch+ git merge。pull的话,拉取远程分支并与本地分支合并,fetch只是拉远程分支,怎么合并,可以自己再做选择。</p>
<pre><code>git push origin master 将本地分支的更新全部推送到远程仓库master分支。
git push origin -d &lt;branchname&gt; 删除远程branchname分支
git push --tags 推送所有标签</code></pre>
<pre><code>git branch 查看本地所有的分支
git branch -r 查看所有远程的分支
git branch -a 查看所有远程分支和本地分支
git branch -D &lt;branchname&gt; 删除本地branchname分支</code></pre>
<pre><code>git merge master 在当前分支上合并master分支过来
git merge --no-ff origin/dev 在当前分支上合并远程分支dev
git merge --abort 终止本次merge,并回到merge前的状态</code></pre>
<p>git reset的作用是修改HEAD的位置,即将HEAD指向的位置改变为之前存在的某个版本.</p>
<pre><code>git reset HEAD file # 仅仅是取消暂存
git checkout file 撤销修改</code></pre>
<h2>回退</h2>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=48c32de67f6644be3c6482ae7ed1915b&amp;file=file.png" alt="" /></p>
<h2>lfs 问题</h2>
<p>可以执行 <code>git reset --hard HEAD^</code> 回退到未提交之前的状态,重新改动文件进行提交。</p>