git修改文件后没提交怎么回复

(1使用git reflog show或git log -g命令来看到所有的作日志) git checkout

gitcommit撤销 gitcommit后怎么撤销gitcommit撤销 gitcommit后怎么撤销


gitcommit撤销 gitcommit后怎么撤销


$ git checkout file-name

例如:git checkout src/com/Android/.../xxx.ja场景: 你在一个更早期的 commit 里忘记了加入一个文件,如果更早的 commit 能包含这个忘记的文件就太棒了。你还没有 push,但这个 commit 不是最近的,所以你没法用 commit --amend.va

比如修改的都是ja文件,不必一个个撤销,可以使用

$ git checkout .ja

作为一次的提交撤销所有修改

$ git checkout .

(2) git rrt

撤销某次作,此次作之前和之后的commit和history都会保留,并且把这次撤销

git rrt HEAD 撤销前一次 commit

git rrt HEAD^ 撤销前前一次 commit

git rrt commit-id (比如:fa042ce57ebbe5bb9c8db709f719cec2c58ee7ff)撤销指定的版本,撤销也会作为一次提交进行保存。

git rrt是提交一个新的版本,将需要rrt的版本的内容再反向修改回去,版本会递增,不影响之前提交的内容

在eclipse里用git,怎么撤销修改

$ git checkout 【行merge作时所在的分支】

修改了两个文件a与b并且没有add和commit,此时这两个文件通过gitstatus-s可以看到M状态,若想单独撤销某一个文件修改,恢复到上一次提交时的状态,可以执行gitcheckout--[filename],即可将filename文件的上一个提交状态检出到当前工作区,filename就是要检出的文件名。不影响其他文件。gitcheckout--a

修正一个 commit 消息

git地址修改需要重新clone、修改地址,现将方法记录如下:1.Clone新地址:

这些 ling commit 平时放着没事,如果太多当你做一些 git 作的时候,比如大量的 ling commit 导致 git rebase 出现如下提示:2.在Eclipse中打开Git Resitory Exploring 视图:

3.在左侧出现所有项目:

4.右键点击要修改的项目:

5.在选项中选择“属性”,弹出配置页面:

6.由于没有修改功能,只好删掉原来的,新添一个,输入新的

直接用用命令吧。

git checkout --

Git怎样撤销一次分支的合并Merge

Hard Reset.

由于太多人问怎么撤销 merge 了,于是 git 出了这份教程,表示在 git 现有的思想体系下怎么达到撤销 merge 的目标。

方法一,reset 到 merge 前的版本,然后再重做接下来的作,要求每个合作者都晓得怎么将本地的 HEAD 都回滚回去:

方法二,当 merge 以后还有别的作和改动时,git 正好也有办法能撤销 merge,用 git rrt:

$ git rrt -m 【要撤销的那条merge线的编号,从1开始计算(怎么看哪条线是几啊?)】 【merge前的版本号】

Finished one rrt.

[ 88edd6d] Rrt "Merge branch 'jk/t-checkout'"

1 files changed, 0 insertions(+), 2 deletions(-)

这样会创建新的 commit 来抵消对应的 merge 作,而且以后 git merge 【那个编号所代表的分支】 会提示:

Already up-to-date.

因为使用方法二会让 git 误以为这个分支的东西都是咱们不想要的。

方法三,怎么撤销方法二commit which is to be rrted does not he to be checked out for that.:

$ git rrt 【方法二撤销merge时提交的commit的版本号,这里是88edd6d】

Finished one rrt.

[ 268e243] Rrt "Rrt "Merge branch 'jk/t-checkout'""

1 files changed, 2 insertions(+), 0 deletions(-)

这样就行了,可以正常 merge 了,不过可能会有很多冲突噢!!

$ git merge jk/t-checkout

Auto-merging test.txt

Merge made by recursive.

test.txt | 1 +

1 files changed, 1 insertions(+), 0 deletions(-)

的,还是觉得顶上那些都麻烦爆了。前端天天用 WebStorm 写代码的看过来: WebStorm 右键点击项目文件或文件夹,有一个:

Local History -> Show History

点开后出现一个窗口,可以看到所有的本地改动。找到场景: 你进行了一些提交,然后意识到你开始 check out 的是 分支。你希望这些提交进到另一个特性(feature)分支里。合适的那份,按左上角那个:

Rrt

按钮,也就是个紫色的弯曲的小箭头就回去了。在文件量不大的时候十分管用,强烈。

如何在git上取消push作

如果只是想回到 pull 之前当前分支所在的commit位置,则可以。比方说你在 分支上,可以用 git reflog 查看 分支历史变动记录,其中应该有一个就是你 pull 之前的那个commit, 你可以用 git reset --hard 来恢复。比如下面的,定你 pull 之前处在 xxxxxx 那个位置,那么可以用 git reset --hard @{1} 恢复。 但是无论如何,没在 Git 中只要提交记录产生,无论你是 reset 、 rebase 还是 commit --amend 等作都没事,最终都能在 git reflog 中找到。那么问题来了,reflog 为什么能够找到?有commit并被 git 就会弹出一个为rrt changes的选项框中,在列表中选中需要撤销的文件。reset --hard 清掉的本地改动是无法通过git恢复的。

撤销一个“已公开”的改变 场景:你已经执行了 git push , 把你的修改发送到了 GitHub,现在你意识到这些 commit 的其中一个是有问题的,你需要撤销那一个 commit. 方法: git rrt 原理: git rrt 会产生一个新的 commit,它和指定 SHA 对应的 ...

在eclipse里用git,怎么撤销修改

场景: 一只猫从键盘上走过,无意中保存了修改,然后破坏了编辑器。不过,你还没有 commit 这些修改。你想要恢复被修改文件里的所有内容 — 就像上次 commit 的时候一模一样。

在eclipse里用git,撤销修改的说明如下:

Rrting changes in the working tree Replace with File in Git Index

Changes which are not yet committed and not yet staged can be rrted for a

ogous view and click Replace With > File in Git

Index. Replace with HEAD

This feature is currently not ailable on single file ll. You can use

Reset to with option hard to forcefully reset

the entire working tree of your reitory back to the state of the HEAD commit

(See "Resetting your current HEAD" below). This operation will rrt all

changes in the working tree and the index. You can't do it on a selected set of

files using EGit yet. Replace with Previous Revision

Changes that are already staged or n committed can be "rrted" by

replacing them with a version from the previous commit. Select a single resource

in the Package Explorer or an ogous view and click Replace With >

Previous Revision. The reitory will determine the last commit that

modified the selected resource and offer to replace the workspace resource with

the contents of this commit.

This is mainly intended for "removing" single files from a commit (when

the current commit). Even though this also w通过git log -g命令来找到需要恢复的信息对应的commitid,可以通过提交的时间和日期来辨别,找到执行reset --hard之前的那个commit对应的commitis on folders and projects, the

results of replacing a folder or project with a "previous revision" may be

unexpected. Rrt using quickdiff

The quickddiff feature can be used to rrt individual changes to a file.

You can rrt by line, block (se range of changes lines) or selection. Select

Rrting changes introduced by a specific commit

Changes which are introduced by a given commit can be rrted by an

automatically created new commit on top of the currently checked out commit. The

Select the commit in the History View, open the context menu and select

Rrt Commit. This rrts the changes that the selected

commit introduces by creating a new commit on top of the currently checked out

commit. Resetting your current HEAD

Git offers the sibility to reset the HEAD of the current branch to any

other commit. It optionally resets the index and the working tree to match that

commit. Note that this action affects all files and folders in the entire

reitory.

You he the option to do a hard reset, a mixed reset and a soft reset. soft - the HEAD points now to the new commit, the index

is updated, the working tree is unchanged

hard - the HEAD points now to the new commit, the index and

the working tree are updated Reset to specific branch or tag

where you can select a branch or a tag. Reset to a specific commit

Select a commit in the History view and open the contextall text and then Rrt selection to rrt a whole file. menu. Here you find

the entries Hard reset, Mixed reset and

Soft reset. Rrt all local and staged changes

This can be done as a special case of reset. If yoeset to the current HEAD

(normally the last commit on your branch) with the option hard

you overwrite the working tree and the index with the content of the HEAD. You

can do this in three ways: Select Team > Reset... on a project. In the dialog

select HEAD or your current branch and switch the radio button to

hard.

Reitories view. This opens a dialog which lets you decide on the reset type.

Choose hard here.

Open the context menu on the HEAD commit in the history view and select

我只知道用命令,而且没觉得用命令麻烦。。

git checkout -- 没什么麻烦的。。。

两步撤销git reset --hard 作

方法: git commit --squash 和 git rebase --autosquash -i

1.git log

通过git branch recover_branch commitid 来建立一个新的分支

通过这一命令,找到需要退回的状态,要回退的commitID,如图例:commit 后的:a259aeeda051701352d470b605382721e698d790 就是对应commitID

2.git在代码中已经进行了修改了,插入了几行的代码,而不想插入这些只有通过删除方式,或者通过撤销方式进行。 reset --hard commitID

如何在 Git 里撤销任何作

前面两列是键:个是选定的命令,对应第二列里的 SHA 确定的 commit。缺省情况下, rebase -i 定每个 commit 都要通过 pick 命令被运用。

撤销一个“已公开”的改变

场景: 你已经执行了 git push, 把你的修改发送到了 GitHub,现在你意识到这些 commit 的其中一个是有问题的,你需要撤销那一个 commit.

方法: git rrt

原理: git rrt 会产生一个新的 commit,它和指定 SHA

对应的 commit 是相反的(或者说是反转的)。如果原先的 commit 是“物质”,新的 commit 就是“反物质” — 任何从原先的

commit 里删除的内容会在新的 commit 里被加回去,任何在原先的 commit 里加入的内容会在新的 commit 里被删除。

这是 Git 最安全、最基本的撤销场景,因为它并不会改变历史 — 所以你现在可以 git push 新的“反转” commit 来抵消你错误提交的 commit。

场景: 你在一条 commit 消息里有个笔误,已经执行了 git commit -m "Fxies bug #42",但在 git push 之前你意识到消息应该是 “Fixes bug #42″。

原理: git commit --amend 会用一个新的 commit 更新并替换最近的 commit ,这个新的 commit 会把任何修改内容和上一个 commit 的内容结合起来。如果当前没有提出任何修改,这个作就只会把上次的 commit 消息重写一遍。

撤销“本地的”修改

方法: git checkout --

原理: git checkout 会把工作目录里的文件修改到 Git 之前记录的某个状态。你可以提供一个你想返回的分支名或特定 SHA ,或者在缺省情况下,Git 会认为你希望 checkout 的是 HEAD,当前 checkout 分支的一次 commit。

记住:你用这种方法“撤销”的任何修改真的会完全消失。因为它们从来没有被提交过,所以之后 Git 也无法帮助我们恢复它们。你要确保自己了解你在这个作里扔掉的东西是什么!(也许可以先利用 git diff 确认一下)

重置“本地的”修改

场景: 你在本地提交了一些东西(还没有 push),但是所有这些东西都很糟糕,你希望撤销前面的三次提交 — 就像它们从来没有发生过一样。

原理: git reset 会把你的代码库历史返回到指定的 SHA 状态。 这样就像是这些提交从来没有发生过。缺省情况下, git reset 会保留工作目录。这样,提交是没有了,但是修改内容还在磁盘上。这是一种安全的选择,但通常我们会希望一步就“撤销”提交以及修改内容 — 这就是 --hard 选项的功能。

在撤销“本地修改”之后再恢复

场景: 你提交了几个 commit,然后用 git reset --hard 撤销了这些修改(见上一段),接着你又意识到:你希望还原这些修改!

方法: git reflog 和 git reset 或 git checkout

原理: git reflog 对于恢复项目历史是一个超棒的资源。你可以恢复几乎 任何东西 — 任何你 commit 过的东西 — 只要通过 reflog。

你可能已经熟悉了 git log 命令,它会显示 commit 的列表。 git reflog 也是类似的,不过它显示的是一个 HEAD 发生改变的时间列表.

一些注意事项:

它涉及的只是 HEAD 的改变。在你切换分支、用 git commit 进行提交、以及用 git reset 撤销 commit 时,HEAD 会改变,但当你用 git checkout -- 撤销时(正如我们在前面讲到的情况),HEAD 并不会改变 — 如前所述,这些修改从来没有被提交过,因此 reflog 也无法帮助我们恢复它们。

git reflog 不会永远保持。Git 会定期清理那些 “用不到的” 对象。不要指望几个月前的提交还一直躺在那里。

你的 reflog 就是你的,只是你的。你不能用 git reflog 来恢复另一个开发者没有 push 过的 commit。

如果你希望准确地恢复项目的历史到某个时间点,用 git reset --hard

如果你希望重建工作目录里的一个或多个文件,让它们恢复到某个时间点的状态,用 git checkout --

如果你希望把这些 commit 里的某一个重新提交到你的代码库里,用 git cherry-pick

利用分支的另一种做法

方法: git branch feature, git reset --hard origin/, and git checkout feature

原情形2:删除倒数第二个Commit理: 你可能习惯了用 git checkout -b 创建新的分支 — 这是创建新分支并马上 check out 的流行捷径 — 但是你不希望马上切换分支。这里, git branch feature 创建一个叫做 feature 的新分支并指向你最近的 commit,但还是让你 check out 在 分支上。

,用 git checkout 切换到新的 feature 分支,并且让你最近所有的工作成果都完好无损。

及时分支,省去繁琐

场景: 你在 分支的基础上创建了 feature 分支,但 分支已经滞后于 origin/ 很多。现在 分支已经和 origin/ 同步,你希望在 feature 上的提交是从现在开始,而不是也从滞后很多的地方开始。

方法: git checkout feature 和 git rebase

原理: 要达到这个效果,你本来可以通过 git reset (不加 --hard, 这样可以在磁盘上保留修改) 和 git checkout -b 然后再重新提交修改,不过这样做的话,你就会失去提交历史。我们有更好的办法。

git rebase 会做如下的事情:

首先它会找到你当前 check out 的分支和 分支的共同祖先。

然后它 reset 当前 check out 的分支到那个共同祖先,在一个临时保存区存放所有之前的提交。

然后它把当前 check out 的分支提到 的末尾部分,并从临时保存区重新把存放的 commit 提交到 分支的一个 commit 之后。

场景: 你向某个方向开始实现一个特性,但是半路你意识到另一个方案更好。你已经进行了十几次提交,但你现在只需要其中的一部分。你希望其他不需要的提交统统消失。

方法$ git rebase -i dd61ab32^: git rebase -i

原理: -i 参数让 rebase 进入“交互模式”。它开始类似于前面讨论的 rebase,但在重新进行任何提交之前,它会暂停下来并允许你详细地修改每个提交。

rebase -i 会打开你的缺省文本编辑器,里面列出候选的提交。如下所示:

要丢弃一个 commit,只要在编辑器里删除那一行就行了。如果你不再需要项目里的那几个错误的提交,你可以删除上例中的1、3、4行。

如果你需要保留 commit 的内容,而是对 commit 消息进行编辑,你可以使用 reword 命令。 把列里的 pick 替换为 reword (或者直接用 r)。有人会觉得在这里直接重写 commit 消息就行了,但是这样不管用 —rebase -i 会忽略 SHA 列前面的任何东西。它后面的文本只是用来帮助我们记住 0835fe2 是干啥的。当你完成 rebase -i 的作之后,你会被提示输入需要编写的任何 commit 消息。

如果你需要把两个 commit 合并到一起,你可以使用 squash 或 fixup 命令,如下所示:

squash 和 fixup 会“向上”合并 — 带有这两个命令的 commit 会被合并到它的前一个 commit 里。在这个例子里, 0835fe2 和 6943e85 会被合并成一个 commit, 38f5e4e 和 af67f82 会被合并成另一个。

如果你选择了 squash, Git 会提示我们给新合并的 commit 一个新的 commit 消息; fixup 则会把合并清单里个 commit 的消息直接给新合并的 commit 。 这里,你知道 af67f82 是一个“完了完了….” 的 commit,所以你会留着 38f5e4e as的 commit 消息,但你会给合并了 0835fe2 和 6943e85 的新 commit 编写一个新的消息。

在你保存并退出编辑器的时候,Git 会按从顶部到底部的顺序运用你的 commit。你可以通过在保存前修改 commit 顺序来改变运用的顺序。如果你愿意,你也可以通过如下安排把 af67f82 和 0835fe2 合并到一起:

修复更早期的 commit

原理: git commit --squash 会创建一个新的 commit ,它带有一个 commit 消息,类似于 squash! Earlier commit。 (你也可以手工创建一个带有类似 commit 消息的 commit,但是 commit --squash 可以帮你省下输入的工作。)

如果你不想被提示为新合并的 commit 输入一条新的 commit 消息,你也可以利用 git commit --fixup 。在这个情况下,你很可能会用commit --fixup ,因为你只是希望在 rebase 的时候使用早期 commit 的 commit 消息。

rebase --autosquash -i 会激活一个交互式的 rebase 编辑器,但是编辑器打开的时候,在 commit 清单里任何 squash! 和 fixup! 的 commit 都已经配对到目标 commit 上了,如下所示:

在使用 --squash 和 --fixup 的时候,你可能不记得想要修正的 commit 的 SHA 了— 只记得它是前面第 1 个或第 5 个 commit。你会发现 Git 的 ^ 和 ~ 作符特别好用。HEAD^ 是 HEAD 的前一个 commit。 HEAD~4 是 HEAD 往前第 4 个 – 或者一起算,倒数第 5 个 commit。

停止一个文件

场景: 你偶然把 application.log 加到代码库里了,现在每次你运行应用,Git 都会报告在 application.log 里有未提交的修改。你把 .login 放到了 .gitignore 文件里,可文件还是在代码库里 — 你怎么才能告诉 Git “撤销” 对这个文件的呢?

方法: git rm --cached application.log

原理: 虽然 .gitignore 会阻止 Git 文件的修改,甚至不关注文件是否存在,但这只是针对那些以前从来没有过的文件。一旦有个文件被加入并提交了,Git 就会持续关注该文件的改变。类似地,如果你利用 git add -f 来强制或覆盖了 .gitignore, Git 还会持续改变的情况。之后你就不必用-f 来添加这个文件了。

如果你希望从 Git 的对象中删除那个本应忽略的文件, git rm --cached 会从对象中删除它,但让文件在磁盘上保持原封不动。因为现在它已经被忽略了,你在 git status 里就不会再看见这个文件,也不会再偶然提交该文件的修改了。

git rrt和git reset的区别

会有每个提交信息的 commitId

git rrt 是撤销某次作,此次作之前的commit都会被保留

Select Team -> Reset... on a project. This opens a dialog

git reset 是撤销某次提交,但是此次之后的修改都会被退回到暂存区

下一步,在提交任何新的 commit 之前,用 git reset --hard 把 分支倒回 origin/ 。不过别担心,那些 commit 还在 feature 分支里。

具体一个例子,设有三个commit, git st:

commit3: add test3.c

commit1: add test1.c

git log可以看到:

commit1:add test1.c

git status 没有任何变化

如果换做执行git reset --soft(默认) HEAD~1后,运行git log

commit1: add test1.c

运行git status, 则test3.c处于暂存区,准备提交。

如果换做执行git reset --hard HEAD~1后,

显示:HEAD is now at commit2,运行git log

commit1: add test1.c

运行git st, 没有任何变化

另外:

git rrt 是撤消该commit,作为一个新的commit。

git如何撤销pull命令。

当执行git rrt HEAD~1时, commit2被撤销了

1、输入 1,回车就会进入到自己项目的这个git仓库所在文件夹了。

2、然后点击输入命令代码“git reflog”,回车确定执行命令。

3、然后找到需要回退的版本,执行命令:git reset --hard HEAD@{n},回车确定、

4、然后选择想要退回的版本,输入命令,例如:执行:git reset --hard 61a942c,回车确定。

$ git reflog

3b4946a Right click and select Reset... on any branch or tag in the@{0}: merge origin/

87e70 @{1}: xxxxxxx

$ git reflog

3b4946a @{方法: git reset 或 git reset --hard 0}: merge origin/

87e70 @{1}: xxxxxxx

丢弃的 commit 去哪了

pick dd61ab32

首先,要明白提交的 commit 纪录一旦产生就一直都在,无论是 reset 还是 rebase 等作并没有对 commit 纪录进程删除和更改,只是修改了指向 commit 的 HEAD 指针而已。

大量的撤销/恢复

当我们通过 git commit --amend 或 git rebase 创建一个新的提交或者通过 git reset --hard HEAD^ 撤销 commit 时,旧的提交仍然保留着呢。您通过 git log 看不到它们的原因是因为没有指向它们的指针,这些 commit 就是 ling commit(悬挂的 commit)。

你可以通过 git fsck --lost-found 命令查看 ling commit 列表。

例如,我们通过 git reset --hard HEAD^ 撤销 commit 产生了 ling commit,然后通过 git fsck --lost-found 命令查看 ling c当执行完git reset --hard 作后,发现并不是自己想要的结果,可以通过以下步骤实现回退:ommit 列表:

这时你就得手动删除了,也很简单: