git various undo operations

Source: Internet
Author: User

Undo git Add Operation
git reset HEAD <file>   # 取消add操作并保留修改-- <file> #若继续该命令,则会删除掉刚刚的修改内容
Undo Git commit Operation
reset --soft <commit_id>   #可以回退到某个commit并保存之前的修改  <commit_id>从git log中取,取前7位即可reset --hard <commit_id>  #回退到某个commit不保留之前的修改
Undo the commit after you revoke the GIT push action push
<commit_id>

Principle: Git revert will produce a new commit, which is the opposite (or reverse) of the commit that corresponds to the specified SHA. Any content deleted from the original commit will be added back in the new commit, and any content added to the original commit will be deleted in the new commit. This is the safest and most basic undo scenario for Git, because it doesn't change history-so you can now git push a new "invert" commit to offset the commit you mistakenly committed.

Delete some files that should not be submitted after push delete the file on the remote branch, and also delete the files from the local repository:
file"test delete"   name
Delete files on the remote branch, but also keep the files for the local repository
--cached filename commit -m "delete" git push origin branch name
Delete a folder on a remote branch, but also keep the folders and files for the local warehouse
--cached directorycommit -m "test"git push origin branch name

Reference
git revokes the commit and saves the previous changes
How to undo (almost) any action in Git

git various undo operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.