eclipse中git插件使用 git config git init git clone git add git commit git diff git reset git status git rm git log git show git tag git branch git checkout git merge git remote git push git pull git stash

1,首先看下文件的几个工作区:Unstaged Changes(本地工作空间),Staged Changes(Add to Index操作之后代码存放的地方),Local Repository(本地仓库),Remote Repository(远程仓库)。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

图片中只展示两个工作区:Unstaged Changes,Staged Changes(中文名叫暂存区,一般存放在".git目录下"的index(.git/index)文件中,所以我们把暂存区有时也叫索引(index)),但是当你点击提交(Commit)按钮的时候,它就会被提交到本地仓库(Local Repository)了。如果你点击左边的Commit and Push,代码就会被提交到本地仓库(Local Repository),然后推送远程仓库(Remote Repository)。

你也可以点击Push Branch,代码被推送到远程仓库(Remote Repository)。操作方法如下:

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

选择你刚才提交的本地分支,如上图,带有local标识的,然后右击,再选择Push Branch。就被推送到远程仓库(Remote Repository)了。

2,eclipse中git的其他操作介绍

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

右击git工程文件a-->Team-->commit:提交到本地仓库(Local Repository)。

右击git工程文件a-->Team-->Push to Upstream:把本地仓库(Local Repository)代码提交到远程仓库(Remote Repository)。

右击git工程文件a-->Team-->Fetch from Upstream:从远程获取最新版下载到本地仓库(Local Repository),不会自动merge。示例

git fetch origin master
git log -p master..origin/master
git merge origin/master

或者
git fetch origin master:tmp git diff tmp  git merge tmp

以上命令的含义:
首先从远程的origin的master主分支下载最新的版本到origin/master分支上
然后用git diff比较本地的master分支和origin/master分支的差别
最后进行合并

右击git工程文件a-->Team-->Push branch 'master':提交本地分支代码到远程服务器,就是在远程服务器上新建一个分支。

右击git工程文件a-->Team-->Pull:从远程获取最新版本并merge到本地。它把过程的细节都隐藏了起来,以至于你不用去了解git中各种类型分支的区别和使用方法。而且你的本地工作目录在未经确认的情况下就会被远程分支更新。当然,除非你关闭所有的安全选项,否则git pull在你本地工作目录还不至于造成不可挽回的损失,但很多时候我们宁愿做的慢一些,也不愿意返工重来。慎用。尽量用git fetch和git merge代替示例

git pull origin master

上述命令其实相当于git fetch 和 git merge。在实际使用中,git fetch更安全一些。因为在merge前,我们可以用git diff命令查看更新情况,然后再决定是否合并。

右击git工程文件a-->Team-->Synchronize Workspace:把本地代码跟本地仓库(Local Repository)上的代码进行比对,是否有冲突。

右击git工程文件a-->Team-->merge:把本地代码合并到另一个分支上,点击之后出现弹出框,让你选择另一分支。

右击git工程文件a-->Team-->rebase:它比较高级,可以重写所有的信息,不过据说也很危险。

右击git工程文件a-->Team-->reset:放弃修改,同步运程仓库(Remote Repository),回退到以前某个版本。

2,你提交文件了,发现该错了,想撤回,怎么办?

其中:Working Area对应eclipse中git插件的状态是Unstaged Changes,Staging Area对应eclipse中git插件的状态是Staged Changes,后面的两个阶段跟eclipse中git插件的状态是一样的意思。git -commit -a表示从workspace直接到local repository。git -checkout HEAD表示从local repository到workspace。git -checkout表示从Staging Area到workspace。git -diff HEAD表示从local repository到workspace。git -diff表示从Staging Area到workspace。

4个阶段分为3个步骤:

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

第一步--》第二步:git add .把所有文件放入暂存区。

第二步--》第三步:git commit -m "comment",其中comment表示提交的注释。

第三步--》第四步:git push把所有文件从本地仓库推送进远程仓库。

当然,以上4个区,进入每一个区成功之后会产生一个状态,再加上最初始的一个状态,一共是5种状态。以下我们把这5种状态分别命名为:

未修改(Origin):从git服务器上下载下来的文件的状态,原始状态

已修改(Modified):Working Area

已暂存(Staged):Staging Area

已提交(Committed):Local Repository

已推送(Pushed):Remote Repository

撤销修改的步骤:

1)检查修改

了解了基本概念之后,我们来谈一谈犯错误之后如何撤销的问题。首先,我们要了解如何检查这3个步骤当中每一个步骤修改了什么,然后才好判断有没有修改成功。检查修改的二级命令都相同,都是diff,只是参数有所不同。

已修改,未暂存

git diff

首先,我们来看一下,如果我们只是简单地在浏览器里保存了一下文件,但是还没有做git add .之前,即已修改(Modified):Working Area,我们如何检查有哪些修改。我们先随便拿一个文件来做一下实验:

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

我们在文件开头的第2行胡乱加了4个数字1234,存盘,这时文件进入了已修改状态,但是还没有进入暂存区,我们运行git diff,结果如下:

diff --git a/index.md b/index.md

index 73ff1ba..1066758 100644

--- a/index.md

+++ b/index.md

@@ -1,5 +1,5 @@

---

-layout: main

+1234layout: main

color: black

---

git diff的结果告诉我们哪些文件已经做了哪些修改。

已暂存,未提交,即已暂存(Staged):Staging Area

git diff --cached

现在我们把修改放入暂存区看一下。先执行git add .,然后执行git diff,你会发现没有任何结果:

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

这说明git diff这个命令只检查我们的工作区和暂存区之间的差异,如果我们想看到暂存区和本地仓库之间的差异,就需要加一个参数git diff --cached:

diff --git a/index.md b/index.md

index 73ff1ba..1066758 100644

--- a/index.md

+++ b/index.md

@@ -1,5 +1,5 @@

---

-layout: main

+1234layout: main

color: black

---

这时候我们看到的差异是暂存区和本地仓库之间的差异。

已提交,未推送,即已提交(Committed):Local Repository

git diff master origin/master

现在,我们把修改从暂存区提交到本地仓库(Local Repository),再看一下差异。先执行git commit,然后再执行git diff --cached,没有差异,执行git diff master origin/master,可以看到差异:

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

在这里,master就是你的本地仓库(Local Repository),而origin/master就是你的远程仓库(Remote Repository),master是主分支的意思,因为我们都在主分支上工作,所以这里两边都是master,而origin就代表远程。

2,开始撤销修改

了解清楚如何检查各种修改之后,我们开始尝试各种撤销操作。

已修改,未暂存,即Working Area

如果我们只是在编辑器里修改了文件,但还没有执行git add .,这时候我们的文件还在工作区,并没有进入暂存区,我们可以用:

git checkout .

或者

git reset --hard

来进行撤销操作。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

可以看到,在执行完git checkout .之后,修改已被撤销,git diff没有任何内容了。

一对反义词 git add .的反义词是git checkout .。做完修改之后,如果你想向前走一步,让修改进入暂存区,就执行git add .,如果你想向后退一步,撤销刚才的修改,就执行git checkout .。

已暂存,未提交,即Staging Area

你已经执行了git add .,但还没有执行git commit -m "comment"。这时候你意识到了错误,想要撤销,你可以执行:

git reset

git checkout .

或者

git reset --hard

git reset只是把修改退回到了git add .之前的状态,也就是说文件本身还处于已修改未暂存状态,你如果想退回未修改状态,还需要执行git checkout .。

或许你已经注意到了,以上两个步骤都可以用同一个命令git reset --hard来完成。是的,就是这个强大的命令,可以一步到位地把你的修改完全恢复到未修改的状态。

已提交,未推送,即Local Repository

你的手太快,你既执行了git add .,又执行了git commit,这时候你的代码已经进入了你的本地仓库,然而你后悔了,怎么办?不要着急,还有办法。

git reset --hard origin/master

还是这个git reset --hard命令,只不过这次多了一个参数origin/master,正如我们上面讲过的,origin/master代表远程仓库,既然你已经污染了你的本地仓库,那么就从远程仓库把代码取回来吧。

已推送,即Remote Repository

很不幸,你的手实在是太快了,你既git add了,又git commit了,并且还git push了,这时你的代码已经进入远程仓库。如果你想恢复的话,还好,由于你的本地仓库和远程仓库是等价的,你只需要先恢复本地仓库,再强制push到远程仓库就好了:

git reset --hard HEAD

git push -f

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

总结:

以上4种状态的撤销我们都用到了同一个命令git reset --hard,前2种状态的用法甚至完全一样,所以只要掌握了git reset --hard这个命令的用法,从此你再也不用担心提交错误了。

本文再贡献其他git命令:

git cherry-pick

git config

git init

git clone

git add

git commit

git diff

git reset

git status

git rm

git log

git show

git tag

git branch

git checkout

git merge

git remote

git push

git pull

git stash

所以,让我们开始吧!

git cherry-pick

用法:git cherry-pick [-x] <commit id>,其中可以加-x参数,表示保留原提交者信息,如果不加参数,就不保留。

注意:当执行完 cherry-pick 以后,将会生成一个新的提交;这个新的提交的哈希值和原来的不同,但标识名 一样;如果在cherry-pick 的过程中出现了冲突,找到该文件的最新一次提交记录,即commid id,然后再执行上面的命令,或者也可以用git status来查看哪些文件出现冲突,修改好了之后,再用命令git add 文件名和git commit -c <新的commit号码>。Git从1.7.2版本开始支持批量cherry-pick,就是一次可以cherry-pick一个区间的commit。命令格式如下:

git cherry-pick <start-commit-id>..<end-commit-id>
或
git cherry-pick <start-commit-id>^..<end-commit-id>

前者表示把<start-commit-id>到<end-commit-id>之间(左开右闭,不包含start-commit-id)的提交cherry-pick到当前分支;后者表示把<start-commit-id>到<end-commit-id>之间(闭区间,包含start-commit-id)的提交cherry-pick到当前分支。其中,<start-commit-id>到<end-commit-id>只需要commit-id的前6位即可,并且<start-commit-id>在时间上必须早于<end-commit-id>。注:以上合并,需要手动push代码。

git config

用法:git config -global user.name“[name]”

用法:git config -global user.email“[email address]”

此命令分别设置要与提交一起使用的作者姓名和电子邮件地址。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git init

用法: git init [repository name]

此命令用于启动新存储库。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git clone

用法: git clone [url]

此命令用于从现有URL获取存储库。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git add

用法: git add [file]

此命令将文件添加到暂存区域。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法: git add *

此命令将一个或多个添加到暂存区域。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git commit

用法:git commit -m“[Type in the commit message]”

此命令在版本历史记录中永久记录或快照文件。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法: git commit -a

此命令使用git add命令提交你添加的所有文件,并提交自此以后你更改的所有文件。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git diff

用法:git diff

此命令显示尚未暂存的文件差异。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git diff -staged

此命令显示暂存区域中的文件与当前的最新版本之间的差异。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git diff [first branch] [second branch]

此命令显示所提到的两个分支之间的差异。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git reset

用法:git reset [file]

此命令取消暂存文件,但它保留文件内容。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git reset [commit]

此命令撤消指定提交后的所有提交,并在本地保留更改。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git reset -hard [commit]

此命令会丢弃所有历史记录并返回指定的提交。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git status

用法:git status

此命令列出了必须提交的所有文件,其中包括已修改(Unstaged Changes,即Working Area)的文件和没有加入git追踪的文件。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git rm

用法:git rm [file]

此命令从工作目录中删除该文件并分阶段删除。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git log

用法:git log

此命令用于列出当前分支的版本历史记录。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git log -follow [file]

此命令列出文件的版本历史记录,包括文件的重命名。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git show

用法:git show [commit]

此命令显示指定提交的元数据和内容更改。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git tag

用法:git tag[commitID]

此命令用于为指定的提交提供标记。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git branch

用法:git branch

此命令列出当前存储库中的所有本地分支。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git branch [branch name]

此命令创建一个新分支。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git branch -d [branch name]

此命令删除功能分支。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git checkout

用法:git checkout [branch name]

此命令用于从一个分支切换到另一个分支。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git checkout -b [branch name]

此命令创建一个新分支并切换到它。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git merge

用法:git merge [branch name]

此命令将指定分支的历史记录合并到当前分支中。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git remote

用法:git remote add [variable name] [Remote Server Link]

此命令用于将本地存储库连接到远程服务器。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git push

用法:git push [variable name] master

此命令将master分支的已提交更改发送到远程存储库。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git push [variable name] [branch]

此命令将分支提交发送到远程存储库。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git push -all [variable name]

此命令将所有分支推送到远程存储库。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git push [variable name]:[branch name]

此命令删除远程存储库上的分支。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git pull

用法:git pull [Repository Link]

此命令将远程服务器上的更改提取并合并到你的工作目录。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

git stash

用法:git stash save

此命令临时存储所有已修改的跟踪文件。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git stash pop

此命令可恢复最近隐藏的文件。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git stash list

此命令列出所有存储的更改集。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

 

用法:git stash drop

此命令会丢弃最近隐藏的变更集。

eclipse中git插件使用
git config
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash

本文转自:https://www.toutiao.com/a6586232599520215556/?tt_from=mobile_qq&utm_campaign=client_share&timestamp=1533516837&app=news_article&utm_source=mobile_qq&iid=39062783162&utm_medium=toutiao_android&group_id=6586232599520215556

https://www.toutiao.com/a6581719073296482823/?tt_from=mobile_qq&utm_campaign=client_share&timestamp=1532498727&app=news_article&utm_source=mobile_qq&iid=38958718850&utm_medium=toutiao_android