<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>运达&#039;s  blog &#187; Git</title>
	<atom:link href="https://www.yunda51.com/?cat=136&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>https://www.yunda51.com</link>
	<description>运达的博客</description>
	<lastBuildDate>Wed, 12 Nov 2025 07:58:26 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0.19</generator>
	<item>
		<title>Git基本常用命令</title>
		<link>https://www.yunda51.com/?p=1862</link>
		<comments>https://www.yunda51.com/?p=1862#comments</comments>
		<pubDate>Mon, 18 Dec 2017 07:13:52 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1862</guid>
		<description><![CDATA[1、创建分支,并跳转到该分支。 git checkout -b xxxx 2、跳转到已有分支 git chec<a href="https://www.yunda51.com/?p=1862" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<pre class="wp-code-highlight prettyprint">
1、创建分支,并跳转到该分支。
	git checkout -b xxxx

2、跳转到已有分支
	git checkout xxxx

3、提交文件的必要步骤：
	说明：现在你要提交你本地的dev分支到远端dev分支上。
	git pull origin dev   (##拉取远端的dev分支文件。此步骤为必备步骤)
	git add xxx   (##将文件添加到提交的目录里面)
	git commit -m &quot;标注你此次提价的文件说明&quot;  (##提交文件)
	git push origin/dev dev
	
4、合并分支：
	说明：现在你需要把“dali”分支合并到“dev”分支上
	git checkout dev     (##首先切换到dev分支上)
	git merge dali      (##将dali分支合并到当前分支的命令)

5、查看历史提交版本：
	git reflog  (##查看当前分支的提交历史)
	git log --graph     (##查看具体的分支及提交信息)
	git log --graph --pretty=oneline --abbrev-commit    (##具体查看的简化版，强烈推荐使用。不谢)
以下是推荐使用命令的使用效果：
* f320f1a hehe
*   a7cd34b hehe
|\
| * d20802a test
| * cd18f41 youyou
* | 8b7c51d eeh
|/
* a3dbb86 测试代码

6、版本回撤：
	git reset --hard xxxxxx    (##为历史提交版本的前7位字符串)

7、当你只想更新远端分支的某一个文件时：
	git fetch
	git checkout origin/dev -- xxxx(文件名)
	
8、撤下某个提交的文件
	git reset -head xxxxx 

</pre>
<p>转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a> 原文地址：<a href="http://www.yunda51.com/1862.html">http://www.yunda51.com/1862.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1862</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git的基本操作指令</title>
		<link>https://www.yunda51.com/?p=1762</link>
		<comments>https://www.yunda51.com/?p=1762#comments</comments>
		<pubDate>Fri, 05 May 2017 02:19:34 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1762</guid>
		<description><![CDATA[1.1.0git创建密钥 $ ssh-keygen -t rsa //创建密钥 $ cat ~/.ssh/id<a href="https://www.yunda51.com/?p=1762" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p><strong>1.1.0git创建密钥</strong></p>
<pre class="wp-code-highlight prettyprint">
$ ssh-keygen -t rsa   //创建密钥
$ cat ~/.ssh/id_rsa.pub //查看密钥
git clone ssh://git@192.168.199.154:52113/yunda/router.git  //克隆
git add  aa.php  //添加   touch ceshi.php 创建php文件
git status   //查看状态
git commit -m &quot;php用例&quot;;    //提交并添加注释
git push //推
git pull //拉取
</pre>
<p><strong>1.1.1git提交数据</strong><br />
我们可以简单的把工作目录理解成是一个被git服务程序管理的目录，githi时刻的追踪目录类文件的改动，另外在安装好了git服务程序后，默认就会城建好了一个叫做master的分支，我们直接可以提交数据了。</p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1~]# mkdir sutongwang  #创建本地工作目录
[root@git-node1~]# cd sutongwang/     #进入本地工作目录
[root@git-node1 sutongwang]# git init  #初始为git工作目录
Initialized empty Git repository in /root/sutongwang/.git/
[root@git-node1 sutongwang]# touch readme.txt  #创建文件
[root@git-node1 sutongwang]# git status  #查看git状态
#Untracked files:
#   (use &quot;git add &lt;file&gt;...&quot; toinclude in what will be committed)
#       readme.txt  #发现新建的readme.txt文件
…

[root@git-node1sutongwang]# git add readme.txt  #git添加文件至暂存区
[root@git-node1 sutongwang]# git status  #再次查看状态
#Changes to be committed:
#   (use &quot;git rm --cached &lt;file&gt;...&quot; to unstage)
#       new file:   readme.txt#发现新建立的文件readme.txt已经变绿
…
 
[root@git-node1 sutongwang]# git commit -m &quot;the first commit&quot;  #git cmmit提交暂存取文件至git版本仓库
[master (root-commit) dde9e40] the first commit1 file changed, 1 insertion(+)
 create mode 100644 readme.txt
</pre>
<p><strong>1.1.2git移除数据</strong><br />
有些时候会把已经添加早暂存区的文件移除，但仍希望文件在工作目录中不丢失，换句话说，就是把问价从追踪清单中删除。</p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# touch database  #建立文件
[root@git-node1 sutongwang]# git add database   #添加文件至暂存区
[root@git-node1 sutongwang]# git status  #查看当前git状态
# On branch master
# Your branch is ahead of &#039;origin/master&#039; by 4 commits.
#   (use &quot;git push&quot; to publish your local commits)
#
# Changes to be committed:
#   (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)
#
#       new file:   database
[root@git-node1 sutongwang]# git rm --cached database  #将文件从git暂存区域的追踪列表移除(并不会删除当前工作目录内的数据文件)
rm &#039;database&#039;
[root@git-node1 sutongwang]# git status  #此时文件已经是未追踪状态了
# On branch master
#Untracked files:
#   (use &quot;git add &lt;file&gt;...&quot; to include in what will be committed)
#
#       database
no changes added to commit (use &quot;git add&quot; and/or &quot;git commit -a&quot;)
#如果想将文件数据从git暂存区和工作目录一起删除，可以做如下操作。
[root@git-node1 sutongwang]# git add database  #再将database文件提交到git暂存区
[root@git-node1 sutongwang]# git rm -f database  #但如果在删除之前数据文件已经被放入到暂存区域的话，git会担心你误删未提交的文件而报错信息，此时可追加强制删除-f参数。
rm &#039;database&#039;
[root@git-node1 sutongwang]# ls  #查看工作区也没database文件
LICENSE  deployhelp.md  readme.txt
[root@git-node1 sutongwang]# git status  #查看当前状态
# Onbranch master
no changes added to commit (use &quot;git add&quot; and/or &quot;git commit -a&quot;)
</pre>
<p><strong>1.1.3git移动数据</strong></p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# git mv readme.txt test.txt  #git如果要修改文件名称,则使用git mv命令
[root@git-node1 sutongwang]# git status  #查看状态发现下次提交会有一个改名操作
# On branch master
# Changes to be committed:
#   (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)
#
#       renamed:    readme.txt -&gt; test.txt
[root@git-node1 sutongwang]# git commit -m &quot;changed name&quot;  #提交到git版本仓库
[master 88f3791] changed name
 2 files changed, 31 deletions(-)
 delete mode 100644 1
 rename readme.txt =&gt; test.txt (100%)
 
#其实可以如下方法改名
[root@git-node1 sutongwang]# mv test.txt readme.txt  #先修改名称
[root@git-node1 sutongwang]# git rm test.txt  #然后删除git版本仓库内的文件快照
rm &#039;test.txt&#039;
[root@git-node1 sutongwang]# git add readme.txt  #最后再将新的文件添加进入
[root@git-node1 sutongwang]# git commit -m &quot;changed the file name&quot;  #提交至git版本仓库
[master 2caa209] changed the file name
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename test.txt =&gt; readme.txt (100%)
</pre>
<p><strong>1.1.4git的历史记录：</strong></p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# git log  #查看提交历史记录
commit 2caa2090efa1aaf5c32524a13c500c1524e0a5ee
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:32:53 2016 +0800
 
    changed the file name
 
commit 88f379175b5ead7e0d84e47bd6db6f5a3b072921
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:31:03 2016 +0800
 
    changed name
 
commit 76c486fcf5d70b6a443ba9e7dad209c6722c8bee
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:22:39 2016 +0800
 
    tet
[root@git-node1 sutongwang]# git log -2  #查看最近几条记录
commit 2caa2090efa1aaf5c32524a13c500c1524e0a5ee
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:32:53 2016 +0800
 
    changed the file name
 
commit 88f379175b5ead7e0d84e47bd6db6f5a3b072921
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:31:03 2016 +0800
 
    changed name
[root@git-node1 sutongwang]#
[root@git-node1 sutongwang]# git log -p -1  #-p显示每次提交的内容差异,例如仅查看最近一次差异
commit 2caa2090efa1aaf5c32524a13c500c1524e0a5ee
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:32:53 2016 +0800
 
    changed the file name
 
diff --git a/readme.txt b/readme.txt
new file mode 100644
index 0000000..a9b574e
--- /dev/null
+++ b/readme.txt
@@ -0,0 +1,3 @@
+1 hehe
+Create new mode two
+Create new branch is linux
diff --git a/test.txt b/test.txt
deleted file mode 100644
index a9b574e..0000000
--- a/test.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-1 hehe
-Create new mode two
-Create new branch is linux
[root@git-node1 sutongwang]# git log --stat -2 #--stat简要显示数据增改行数，这样能够看到提交中修改过的内容，对文件添加或移动的行数，并在最后列出所有增减行的概要信息
commit 2caa2090efa1aaf5c32524a13c500c1524e0a5ee
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:32:53 2016 +0800
 
    changed the file name
 
 readme.txt | 3 +++
 test.txt| 3 ---
 2 files changed, 3 insertions(+), 3 deletions(-)
 
commit 88f379175b5ead7e0d84e47bd6db6f5a3b072921
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:31:03 2016 +0800
 
    changed name
 
 1| 31 -------------------------------
 readme.txt |3 ---
 test.txt|  3 +++
 3 files changed, 3 insertions(+), 34 deletions(-)
[root@git-node1 sutongwang]# git log --pretty=oneline #--pretty根据不同的格式展示提交的历史信息
2caa2090efa1aaf5c32524a13c500c1524e0a5ee changed the file name
88f379175b5ead7e0d84e47bd6db6f5a3b072921 changed name
76c486fcf5d70b6a443ba9e7dad209c6722c8bee tet
[root@git-node1 sutongwang]# git log --pretty=fuller -2 #以更详细的模式输出提交的历史记录
commit 2caa2090efa1aaf5c32524a13c500c1524e0a5ee
Author:     sutongwang &lt;sutongwang@mail.com&gt;
AuthorDate: Sat Jan 16 18:32:53 2016 +0800
Commit:     sutongwang &lt;sutongwang@mail.com&gt;
CommitDate: Sat Jan 16 18:32:53 2016 +0800
 
    changed the file name
 
commit 88f379175b5ead7e0d84e47bd6db6f5a3b072921
Author:     sutongwang &lt;sutongwang@mail.com&gt;
AuthorDate: Sat Jan 16 18:31:03 2016 +0800
Commit:     sutongwang &lt;sutongwang@mail.com&gt;
CommitDate: Sat Jan 16 18:31:03 2016 +0800
 
    changed name
 
还可以使用format参数来指定具体的输出格式，这样非常便于后期编程的提取分析哦，常用的格式有：
%s  提交说明。
%cd 提交日期。
%an 作者的名字。
%cn 提交者的姓名。
%ce 提交者的电子邮件。
%H  提交对象的完整SHA-1哈希字串。
%h  提交对象的简短SHA-1哈希字串。
%T  树对象的完整SHA-1哈希字串。
%t  树对象的简短SHA-1哈希字串。
%P  父对象的完整SHA-1哈希字串。
%p  父对象的简短SHA-1哈希字串。
%ad 作者的修订时间。
 
[root@git-node1 sutongwang]# git log --pretty=fomat:&quot;%h %cn&quot; #查看当前所有提交记录的简短SHA-1哈希字串与提交着的姓名
fomat:2caa209 sutongwang
fomat:88f3791 sutongwang
fomat:76c486f sutongwang
</pre>
<p><strong>1.1.5git还原数据</strong></p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# echo &quot;Git is a version control system&quot; &gt;&gt; readme.txt #追加一段话
[root@git-node1 sutongwang]# git add readme.txt  #添加至暂存区
[root@git-node1 sutongwang]# git commit -m &quot;introduction software&quot; #提交至git版本仓库
[master 4bf5b29] introduction software
 1 file changed, 1 insertion(+)
 
此时觉得写得不妥，想还原某一次提交的文件快照
[root@git-node1 sutongwang]# git log --pretty=oneline #提交的历史信息
4bf5b296db9678f1851b896ed040fe37e6d7efb5 introduction software
2caa2090efa1aaf5c32524a13c500c1524e0a5ee changed the file name
88f379175b5ead7e0d84e47bd6db6f5a3b072921 changed name
Git服务程序中有一个叫做HEAD的版本指针，当用户申请还原数据时，其实就是将HEAD指针指向到某个特定的提交版本，但是因为Git是分布式版本控制系统，为了避免历史记录冲突，故使用了SHA-1计算出十六进制的哈希字串来区分每个提交版本，另外默认的HEAD版本指针会指向到最近的一次提交版本记录，而上一个提交版本会叫HEAD^，上上一个版本则会叫做HEAD^^，当然一般会用HEAD~5来表示往上数第五个提交版本。
 
[root@git-node1 sutongwang]# git reset --hard HEAD^  #还原历史提交版本上一次
HEAD is now at 2caa209 changed the file name
[root@git-node1 sutongwang]#  cat readme.txt  #查看文件内容(已经还原)
Create new branch is linux
 
刚刚的操作实际上就是改变了一下HEAD版本指针的位置，就是你将HEAD指针放在那里，那么你的当前工作版本就会定位在那里，要想把内容再还原到最新提交的版本，先看查看下提交版本号
[root@git-node1 sutongwang]# git log --pretty=oneline
2caa2090efa1aaf5c32524a13c500c1524e0a5ee changed the file name
88f379175b5ead7e0d84e47bd6db6f5a3b072921 changed name
 
怎么搞得？竟然没有了Introduction software这个提交版本记录？
原因很简单，因为我们当前的工作版本是历史的一个提交点，这个历史提交点还没有发生过Introduction software更新记录，所以当然就看不到了，要是想“还原到未来”的历史更新点，可以用git reflog命令来查看所有的历史记录：
 
[root@git-node1 sutongwang]# git reflog  #查看未来历史更新点
2caa209 HEAD@{0}: reset: moving to HEAD^
4bf5b29 HEAD@{1}: commit: introduction software
2caa209 HEAD@{2}: commit: changed the file name
 
[root@git-node1 sutongwang]# git reset --hard 4bf5b29  #找到历史还原点的SHA-1值后，就可以还原(值不写全,系统会自动匹配)
HEAD is now at 4bf5b29 introduction software
[root@git-node1 sutongwang]# cat readme.txt  #查看文件内容(已经还原)
Create new branch is linux
Git is a version control system
 
如是只是想把某个文件内容还原，就不必这么麻烦，直接用git checkout命令就可以的，先写一段话
[root@git-node1 sutongwang]# echo &quot;Some mistkes words&quot; &gt;&gt; readme.txt
[root@git-node1 sutongwang]# cat readme.txt  #查看内容
Git is a version control system
Some mistkes words
我们突然发现不应该写一句话的,可以手工删除（当内容比较多的时候会很麻烦）,还可以将文件内容从暂存区中恢复
[root@git-node1 sutongwang]# git checkout -- readme.txt
[root@git-node1 sutongwang]# cat readme.txt
Git is a version control system
这其中是有一套规则，如果暂存区中有该文件，则直接从暂存区恢复，如果暂存区没有该文件，则将还原成最近一次文件提交时的快照。
</pre>
<p><strong>1.1.6创建git分支</strong></p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# git branch linux  #创建分支
[root@git-node1 sutongwang]# git checkout linux  #切换分支
Switched to branch &#039;linux&#039;
[root@git-node1 sutongwang]# git branch  #查看当前分支情况,当前分支前有*号
* linux
  master
[root@git-node1 sutongwang]# echo &quot;Create new branch is linux&quot; &gt;&gt; readme.txt   #我们对文件追加一行字符串
[root@git-node1 sutongwang]# git add readme.txt   #提交到暂存区
[root@git-node1 sutongwang]# git commit -m &quot;new branch&quot;  #提交到git版本仓库
[linux 8bf5757] new branch
 1 file changed, 1 insertion(+)
[root@git-node1 sutongwang]# git checkout master  #我们在提交文件后再切回master分支
Switched to branch &#039;master&#039;
[root@git-node1 sutongwang]# cat readme.txt   #查看文件内容,发现并没有新追加的字符串1 hehe
</pre>
<p><strong>1.1.7git合并分支</strong><br />
现在，我们想把linux的工作成果合并到master分支上，则可以使用“git merge“ 命令来讲指定的分支与当前的分支合并<br />
<a href="http://www.yunda51.com/wp-content/uploads/2017/05/图片1.png"><img src="http://www.yunda51.com/wp-content/uploads/2017/05/图片1.png" alt="图片1" width="567" height="228" class="alignnone size-full wp-image-1763" /></a></p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# git branch  #查看是否在master分支
  linux
* master
[root@git-node1 sutongwang]# git merge linux  #合并Linux分支至master
Updating 185d668..8bf5757
Fast-forward
 readme.txt | 1 +
 1 file changed, 1 insertion(+)
[root@git-node1 sutongwang]# cat readme.txt  #查看合并后的readme文件1 hehe
Create new branch is linux
[root@git-node1 sutongwang]# git branch -d linux  #确认合并完成后，可以放心地删除Linux分支
Deleted branch linux (was 8bf5757).
[root@git-node1 sutongwang]# git branch  #删除后，查看branch,只剩下master分支了
*master
</pre>
<p><strong>1.1.8git分支冲突</strong></p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# git checkout -b linux  #创建分支并切换到该分支
[root@git-node1 sutongwang]# git branch  #查看分支
* linux
  master
[root@git-node1 sutongwang]# vim readme.txt  #编辑readme文件
[root@git-node1 sutongwang]# git add readme.txt  #在Linux分支添加readme至暂存区
[root@git-node1 sutongwang]# git commit -m &quot;create two&quot;  #在Linux分支提交readme
[linux 13a42ad] create two
1 file changed, 1 insertion(+), 2 deletions(-)
[root@git-node1 sutongwang]# git checkout master  #切换到master分支
Switched to branch &#039;master&#039;
[root@git-node1 sutongwang]# git branch  #查看是否切换至master分支
  linux
* master
[root@git-node1 sutongwang]# vim readme.txt  #编在master分支上修改readme文件同一行的内容
[root@git-node1 sutongwang]# git add readme.txt  #添加至暂存区
[root@git-node1 sutongwang]# git commit -m &#039;create to master&#039;  #提交至Git版本仓库
[master 75bd55c] create to master
 1 file changed, 1 insertion(+)
[root@git-node1 sutongwang]# git merge linux  #合并Linux分支(冲突)
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
Automatic merge failed; fix conflicts and then commit the result.
#那么此时，我们在master与linux分支上都分别对中readme文件进行了修改并提交了，那这种情况下Git就没法再为我们自动的快速合并了，它只能告诉我们readme文件的内容有冲突，需要手工处理冲突的内容后才能继续合并
[root@git-node1 sutongwang]# cat readme.txt #冲突内容如下
#Git用&lt; &lt;&lt;&lt;&lt;&lt;&lt;，=======，&gt;&gt;&gt;&gt;&gt;&gt;&gt;分割开了各个分支冲突的内容，我们需要手工的删除这些符号，并将内容修改
1 hehe
&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD
=======
&gt;&gt;&gt;&gt;&gt;&gt;&gt; linux
Create new branch is linux
[root@git-node1 sutongwang]# git add readme.txt  #再次添加至暂存区
[root@git-node1 sutongwang]# git commit -m &#039;config&#039;  #提交至git版本仓库
[master eb9bb83] config
[root@git-node1 sutongwang]# git branch -d linux  #最后删除Linux分支结束
Deleted branch linux (was 13a42ad).
[root@git-node1 sutongwang]# git branch  #检查是否删除完毕
* master
</pre>
<p>转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a> 原文地址：<a href="http://www.yunda51.com/1762.html">http://www.yunda51.com/1762.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1762</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
