git-reset

What's the difference between Git Revert, Checkout and Reset?

夙愿已清 提交于 2019-11-26 14:50:30
I am trying to learn how to restore or rollback files and projects to a prior state, and don't understand the difference between git revert , checkout , and reset . Why are there 3 different commands for seemingly the same purpose, and when should someone choose one over the other? These three commands have entirely different purposes. They are not even remotely similar. git revert This command creates a new commit that undoes the changes from a previous commit. This command adds new history to the project (it doesn't modify existing history). git checkout This command checks-out content from

Why are there two ways to unstage a file in Git?

半世苍凉 提交于 2019-11-26 12:33:38
问题 Sometimes git suggests git rm --cached to unstage a file, sometimes git reset HEAD file . When should I use which? EDIT: D:\\code\\gt2>git init Initialized empty Git repository in D:/code/gt2/.git/ D:\\code\\gt2>touch a D:\\code\\gt2>git status # On branch master # # Initial commit # # Untracked files: # (use \"git add <file>...\" to include in what will be committed) # # a nothing added to commit but untracked files present (use \"git add\" to track) D:\\code\\gt2>git add a D:\\code\\gt2>git

How to git reset --hard a subdirectory?

北慕城南 提交于 2019-11-26 11:55:32
问题 UPDATE : This will work more intuitively as of Git 1.8.3, see my own answer. Imagine the following use case: I want to get rid of all changes in a specific subdirectory of my Git working tree, leaving all other subdirectories intact. I can do git checkout . , but git checkout . adds directories excluded by sparse checkout There is git reset --hard , but it won\'t let me do it for a subdirectory: > git reset --hard . fatal: Cannot do hard reset with paths. Again: Why git can't do hard/soft

git undo all uncommitted or unsaved changes

萝らか妹 提交于 2019-11-26 09:14:43
问题 I\'m trying to undo all changes since my last commit. I tried git reset --hard and git reset --hard HEAD after viewing this post. I responds with head is now at 18c3773... but when I look at my local source all the files are still there. What am I missing? 回答1: This will unstage all files you might have staged with git add : git reset This will revert all local uncommitted changes (should be executed in repo root): git checkout . You can also revert uncommitted changes only to particular file

How to revert uncommitted changes including files and folders?

断了今生、忘了曾经 提交于 2019-11-26 09:14:28
问题 Is there a git command to revert all uncommitted changes in a working tree and index and to also remove newly created files and folders? 回答1: You can run these two commands: # Revert changes to modified files. git reset --hard # Remove all untracked files and directories. # '-f' is force, '-d' is remove directories. git clean -fd 回答2: If you want to revert the changes only in current working directory, use git checkout -- . And before that, you can list the files that will be reverted without

What&#39;s the difference between Git Revert, Checkout and Reset?

梦想与她 提交于 2019-11-26 05:56:51
问题 This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated 7 years ago . I am trying to learn how to restore or rollback files and projects to a prior state, and don\'t understand the difference between git revert , checkout , and reset . Why are there 3 different commands for seemingly the same purpose, and when should someone choose one over the other? 回答1: These three commands have entirely different purposes. They are not

Undo a particular commit in Git that&#39;s been pushed to remote repos

↘锁芯ラ 提交于 2019-11-26 02:26:05
问题 What is the simplest way to undo a particular commit that is: not in the head or HEAD Has been pushed to the remote. Because if it is not the latest commit, git reset HEAD doesn\'t work. And because it has been pushed to a remote, git rebase -i and git rebase --onto will cause some problem in the remotes. More so, I don\'t want to modify the history really. If there was bad code, it was there in the history and can be seen. I just want it out in the working copy, and I don\'t mind a reverse

How do I recover/resynchronise after someone pushes a rebase or a reset to a published branch?

喜欢而已 提交于 2019-11-26 01:39:13
问题 We have all heard that one should never rebase published work, that it’s dangerous, etc. However, I have not seen any recipes posted for how to deal with the situation in case a rebase is published. Now, do note that this is only really feasible if the repository is only cloned by a known (and preferably small) group of people, so that whoever pushes the rebase or reset can notify everyone else that they will need to pay attention next time they fetch(!). One obvious solution that I have seen

Undo git reset --hard with uncommitted files in the staging area

让人想犯罪 __ 提交于 2019-11-26 01:05:58
问题 I am trying to recover my work. I stupidly did git reset --hard , but before that I\'ve done only get add . and didn\'t do git commit . Please help! Here is my log: MacBookPro:api user$ git status # On branch master # Changes to be committed: # (use \"git reset HEAD <file>...\" to unstage) # modified: .gitignore ... MacBookPro:api user$ git reset --hard HEAD is now at ff546fa added new strucuture for api Is it possible to undo git reset --hard in this situation? 回答1: You should be able to

Move existing, uncommitted work to a new branch in Git

吃可爱长大的小学妹 提交于 2019-11-26 00:56:20
问题 I started some work on a new feature and after coding for a bit, I decided this feature should be on its own branch. How do I move the existing uncommitted changes to a new branch and reset my current one? I want to reset my current branch while preserving existing work on the new feature. 回答1: Use the following: git checkout -b <new-branch> This will leave your current branch as is, create and checkout a new branch and keep all your changes. You can then make a commit with: git add <files>