[Git] Undo a commit that has already been pushed to the remote repository

If we pushed our changes already to the remote repository we have to pay attention to not change the git history (using commands like rebase, reset, amend etc). Other collaborators of the same repository might already have pulled your changes, thus resulting into horrible, strange merge conflicts if we change the git history. There are some “safer commands” for undoing in such cases.

If you push something we shouldn‘t push to git, we can revert it:

First, using git log to get the commit id you want to revert, then using:

git revert <commit_id>

Then push to git

原文地址:https://www.cnblogs.com/Answer1215/p/10603429.html

时间: 2024-08-01 03:24:59

[Git] Undo a commit that has already been pushed to the remote repository的相关文章

【git基础】Permission denied (publickey). fatal: Could not read from remote repository

运行以下git命令的时候出现错误 git push -u origin master error The authenticity of host 'github.com (13.250.177.223)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes

git undo last commit

$ git commit -m "Something terribly misguided" (1) $ git reset --soft HEAD~ (2) << edit files as necessary >> (3) $ git add ... (4) $ git commit -c ORIG_HEAD (5) 转自: http://stackoverflow.com/questions/927358/how-do-you-undo-the-last-

[Git] Undo my last commit and split it into two separate ones

When you accidentally committed some changes to your branch you have various possibilities to “undo” that operation and add some more changes. One is to use git amend to change the commit message or add new files. But what we want to take out all of

第二章-第二题(练习使用git的add/commit/push/pull/fetch/clone等基本命令)--梁绍楠

题目描述: 每人自己建立一个HelloWorld项目,练习使用git的add/commit/push/pull/fetch/clone等基本命令.比较项目的新旧版本的差别. 使用步骤: (1)创建版本库 选择一个合适的地方,创建一个空目录HelloWorld.而后通过git init把这个目录变成Git可以管理的仓库(目录下会多出了一个.git目录,该目录是git跟踪管理版本库的,勿轻易修改): 编辑hello文件,内容如下: (2)将文件hello放到git仓库 首先,需要设置用户名.邮箱信息

git for c#, commit本地,push服务器

//ok private static void push() { string wkDir = @"E:\DotNet2010\单位工程\Git.Client\lib2Test\ConsoleApplication1\bin\Debug\D2Git\.git"; using (var repo = new Repository(wkDir)) { //此时必须保证存在 one.txt,two.txt 两个文件 string fname = "one.txt"; r

第二章-第二题(练习使用git的add/commit/push/pull/fetch/clone等基本命令)-By郭青云(未完待续)

题目描述: 每人自己建立一个HelloWorld项目,练习使用git的add/commit/push/pull/fetch/clone等基本命令.比较项目的新旧版本的差别. 使用步骤: 未完待续...... 参考文件:http://blog.csdn.net/u012575819/article/details/50553501

第二章-第二题(每人自己建立一个HelloWorld项目,练习使用git的add/commit/push/pull/fetch/clone等基本命令。比较项目的新旧版本的差别。)--by侯伟婷

第二题:每人自己建立一个HelloWorld项目,练习使用git的add/commit/push/pull/fetch/clone等基本命令.比较项目的新旧版本的差别. 下面我将自己的练习结果和个人感受记录如下: 第一步:安装Git,设置自己的账号和邮箱,参见Git教程-廖雪峰的官方网站,网址如下参考资料1所示. 第二步:在Git中新建repository,名叫HelloWorld,并进行初始化,如图所示. 第三步:在HelloWorld版本库中新建了helloWorld.txt文件,用以练习G

git取消本地commit

如果不小心commit了一个不需要commit的文件,可以对其进行撤销. 先使用git log 查看 commit日志 commit 422bc088a7d6c5429f1d0760d008d86c505f4abe Author: zhyq0826 <[email protected]> Date: Tue Sep 4 18:19:23 2012 +0800 删除最近搜索数目限制 commit 8da0fd772c3acabd6e21e85287bdcfcfe8e74c85 Merge: 46

[Git] git revert ( revert commit 和 revert merge)

转载自:http://blog.csdn.net/qinjienj/article/details/7621887 我们难免会因为种种原因执行一些错误的commit / push,git提供了revert命令帮助程序员修复这样的错误. 举个例子,下图是git commit 的历史记录 git revert 命令会通过一个新的commit 来使仓库倒退一个commit,在上例中,如果程序员想要revert 最新的那次commit (Updated to Rails 2.3.2 and edge h