华丽乐章 發表於 2022-10-18 08:48:00

git命令、gitee代码下载与上传

<svg xmlns="http://www.w3.org/2000/svg" style="display: none">
                        <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0)"></path>
                  </svg>
                  <h1>一、git命令</h1>
<h3>1. 配置工具</h3>
<p>为所有本地存储库配置用户信息<br> 设置要关联到提交事务的名称和邮箱</p>
<pre><code class="prism language-bash">$ <span class="token function">git</span> config --global user.name <span class="token string">""</span>

$ <span class="token function">git</span> config --global user.email <span class="token string">""</span>
</code></pre>
<p>启用命令行有用的着色</p>
<pre><code class="prism language-bash">$ <span class="token function">git</span> config --global color.ui auto
</code></pre>
<h3>2. 创建存储库</h3>
<p>启动一个新存储库或从现有 URL 获取一个</p>
<pre><code class="prism language-bash">$ <span class="token function">git</span> init <span class="token punctuation">[</span>project-name<span class="token punctuation">]</span>
<span class="token comment">#Creates a new local repository with the specified name</span>
$ <span class="token function">git</span> clone <span class="token punctuation">[</span>url<span class="token punctuation">]</span>
<span class="token comment">#Downloads a project and its entire version history</span>
</code></pre>
<h3>3. 做出改变</h3>
<p>查看编辑并制作提交事务</p>
<pre><code class="prism language-bash">$ <span class="token function">git</span> status
<span class="token comment">#Lists all new or modified files to be committed</span>
$ <span class="token function">git</span> <span class="token function">add</span> <span class="token punctuation">[</span>file<span class="token punctuation">]</span>
<span class="token comment">#Snapshots the file in preparation for versioning</span>
$ <span class="token function">git</span> reset <span class="token punctuation">[</span>file<span class="token punctuation">]</span>
<span class="token comment">#Unstages the file, but preserve its contents</span>
$ <span class="token function">git</span> <span class="token function">diff</span>
<span class="token comment">#Shows file differences not yet staged</span>
$ <span class="token function">git</span> <span class="token function">diff</span> --staged
<span class="token comment">#Shows file differences between staging and the last file version</span>
$ <span class="token function">git</span> commit -m <span class="token string">""</span>
<span class="token comment">#Records file snapshots permanently in version history</span>
</code></pre>
<h3>4. 组变动</h3>
<p>命名一系列提交并结合已完成的工作</p>
<pre><code class="prism language-bash">$ <span class="token function">git</span> branch
<span class="token comment">#Lists all local branches in the current repository</span>
$ <span class="token function">git</span> branch <span class="token punctuation">[</span>branch-name<span class="token punctuation">]</span>
<span class="token comment">#Creates a new branch</span>
$ <span class="token function">git</span> checkout <span class="token punctuation">[</span>branch-name<span class="token punctuation">]</span>
<span class="token comment">#Switches to the specified branch and updates the working directory</span>
$ <span class="token function">git</span> merge <span class="token punctuation">[</span>branch<span class="token punctuation">]</span>
<span class="token comment">#Combines the specified branch’s history into the current branch</span>
$ <span class="token function">git</span> branch -d <span class="token punctuation">[</span>branch-name<span class="token punctuation">]</span>
<span class="token comment">#Deletes the specified branch</span>
</code></pre>
<h3>5. 重构文件名</h3>
<p>重新定位和删除版本化文件</p>
<pre><code class="prism language-bash">$ <span class="token function">git</span> <span class="token function">rm</span> <span class="token punctuation">[</span>file<span class="token punctuation">]</span>
<span class="token comment">#Deletes the file from the working directory and stages the deletion</span>
$ <span class="token function">git</span> <span class="token function">rm</span> --cached <span class="token punctuation">[</span>file<span class="token punctuation">]</span>
<span class="token comment">#Removes the file from version control but preserves the file locally</span>
$ <span class="token function">git</span> <span class="token function">mv</span> <span class="token punctuation">[</span>file-original<span class="token punctuation">]</span> <span class="token punctuation">[</span>file-renamed<span class="token punctuation">]</span>
<span class="token comment">#Changes the file name and prepares it for commit</span>
</code></pre>
<h3>6. 同步更改</h3>
<p>注册存储库书签并交换版本历史记录</p>
<pre><code class="prism language-bash">$ <span class="token function">git</span> fetch <span class="token punctuation">[</span>bookmark<span class="token punctuation">]</span>
<span class="token comment">#Downloads all history from the repository bookmark</span>
$ <span class="token function">git</span> merge <span class="token punctuation">[</span>bookmark<span class="token punctuation">]</span>/<span class="token punctuation">[</span>branch<span class="token punctuation">]</span>
<span class="token comment">#Combines bookmark’s branch into current local branch</span>
$ <span class="token function">git</span> push <span class="token punctuation">[</span>alias<span class="token punctuation">]</span> <span class="token punctuation">[</span>branch<span class="token punctuation">]</span>
<span class="token comment">#Uploads all local branch commits to GitHub</span>
$ <span class="token function">git</span> pull
<span class="token comment">#Downloads bookmark history and incorporates changes</span>
</code></pre>
<h3>7. 禁止跟踪</h3>
<p>排除临时文件和路径</p>
<pre><code class="prism language-bash">$ <span class="token function">git</span> ls-files --other --ignored --exclude-standard
<span class="token comment">#Lists all ignored files in this project</span>
</code></pre>
<h3>8. 保存片段</h3>
<p>搁置和恢复不完整的更改</p>
<pre><code class="prism language-bash">$ <span class="token function">git</span> stash
<span class="token comment">#Temporarily stores all modified tracked files</span>
$ <span class="token function">git</span> stash list
<span class="token comment">#Lists all stashed changesets</span>
$ <span class="token function">git</span> stash pop
<span class="token comment">#Restores the most recently stashed files</span>
$ <span class="token function">git</span> stash drop
<span class="token comment">#Discards the most recently stashed changeset</span>
</code></pre>
<h3>9. 查看历史</h3>
<p>浏览和检查项目文件的演变</p>
<pre><code class="prism language-bash">$ <span class="token function">git</span> log
<span class="token comment">#Lists version history for the current branch</span>
$ <span class="token function">git</span> log --follow <span class="token punctuation">[</span>file<span class="token punctuation">]</span>
<span class="token comment">#Lists version history for a file, including renames</span>
$ <span class="token function">git</span> <span class="token function">diff</span> <span class="token punctuation">[</span>first-branch<span class="token punctuation">]</span><span class="token punctuation">..</span>.<span class="token punctuation">[</span>second-branch<span class="token punctuation">]</span>
<span class="token comment">#Shows content differences between two branches</span>
$ <span class="token function">git</span> show <span class="token punctuation">[</span>commit<span class="token punctuation">]</span>
<span class="token comment">#Outputs metadata and content changes of the specified commit</span>
</code></pre>
<h3>10. 重做提交</h3>
<p>擦除错误并制作更换历史</p>
<pre><code class="prism language-bash">$ <span class="token function">git</span> reset <span class="token punctuation">[</span>commit<span class="token punctuation">]</span>
<span class="token comment">#Undoes all commits after , preserving changes locally</span>
$ <span class="token function">git</span> reset --hard <span class="token punctuation">[</span>commit<span class="token punctuation">]</span>
<span class="token comment">#Discards all history and changes back to the specified commit</span>
</code></pre>
<h1>二、gitee上代码下载与上传</h1>
<h3>1. 克隆仓库到本地</h3>
<p>在克隆/下载的复制SSH里的<strong>git链接</strong><br> <img src="https://img-blog.csdnimg.cn/3e51b46275ef425181eecca9f56a31b4.png" alt="在这里插入图片描述"><br> 在桌面右击,选择<strong>Git Bash Here</strong>,<br> <img src="https://img-blog.csdnimg.cn/40361b69d724441784aa8e3e9fb4437d.png" alt="在这里插入图片描述"></p>
<p>使用命令git clone +复制的链接<br> <img src="https://img-blog.csdnimg.cn/3bf9f82b17bc4710a0c08cb01eaa9cb9.png" alt="在这里插入图片描述"><br> 克隆成功,可在桌面看到相关文件<br> <img src="https://img-blog.csdnimg.cn/d9d4a32155014cda92824e043c9c316b.png" alt="在这里插入图片描述"></p>
<h3>2. 关联本地工程到远程仓库</h3>
<p>在本地库上使用命令 git remote add把它和 gitee 的远程库关联,如下</p>
<pre><code class="prism language-bash"><span class="token function">git</span> remote <span class="token function">add</span> origin git@gitee.com:username/test1.git
</code></pre>
<p>如果在使用命令 git remote add时报错:</p>
<pre><code class="prism language-bash"><span class="token function">git</span> remote <span class="token function">add</span> origin git@gitee.com:username/test1.git
fatal: remote origin already exists.
</code></pre>
<p>说明本地库已经关联了一个名叫 origin的远程库,此时,可以先用git remote -v查看远程库信息:</p>
<pre><code class="prism language-bash"><span class="token function">git</span> remote -v
origin git@gitee.com:username/test1.git <span class="token punctuation">(</span>fetch<span class="token punctuation">)</span>
origin git@gitee.com:username/test1.git <span class="token punctuation">(</span>push<span class="token punctuation">)</span>
</code></pre>
<p>可以删除已有的远程库</p>
<pre><code class="prism language-bash"><span class="token function">git</span> remote <span class="token function">rm</span> origin
</code></pre>
<p>再关联远程库</p>
<pre><code class="prism language-bash"><span class="token function">git</span> remote <span class="token function">add</span> origin git@gitee.com:username/test1.git
</code></pre>
<h3>3. 上传文件</h3>
<p>在本地添加test_pushFile.txt文件,<br> <img src="https://img-blog.csdnimg.cn/36b290c72ea2422fbe0f21178bb8ab1c.png" alt="在这里插入图片描述"><br> 打开git,执行git的add、commit、push命令,即可将本地文件上传到远程仓库。进入工程文件,添加并提交事务:<br> <img src="https://img-blog.csdnimg.cn/a7e94428b4ab4cd98ea7c4b566795b36.png" alt="在这里插入图片描述"><br> push到远程仓库<br> <img src="https://img-blog.csdnimg.cn/857865d87dff4f1bb17c98c4f30606d1.png" alt="在这里插入图片描述"><br> 刷新gitee网页,看见文件成功上传了。<br> <img src="https://img-blog.csdnimg.cn/670f6f78fbbb4ce7a1255d1580a0e019.png" alt="在这里插入图片描述"></p>
               

</div>
<div id="MySignature" role="contentinfo">
    <div>
<div>作者:aw11</div>
<div>出处:https://www.cnblogs.com/awst-lee/</div>
<div>本文版权归作者和博客园共有,欢迎转载,须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。 </div>
</div><br><br>
来源:https://www.cnblogs.com/awst-lee/p/16801385.html
頁: [1]
查看完整版本: git命令、gitee代码下载与上传