git-reset

What happens to orphaned commits?

﹥>﹥吖頭↗ 提交于 2019-12-03 05:54:13
I have a repo with four commits: $ git log --oneline --decorate 6c35831 (HEAD, master) C4 974073b C3 e27b22c C2 9f2d694 C1 I reset -- soft to the C2 commit and now I have a repo like so: $ git reset e27b22c --soft $ git log --oneline --decorate e27b22c (HEAD, master) C2 9f2d694 C1 Now I add an extra commit, so the log looks like this: $ git log --oneline --decorate 545fa99 (HEAD, master) C5 e27b22c C2 9f2d694 C1 What happened to commits C3 and C4 ? I haven't deleted them, so I assume they are still there, C3 's parent is still C2 . Short answer: Commits C3 and C4 will remain in the Git object

Git: Undo local changes; git add . + git rm?

与世无争的帅哥 提交于 2019-12-03 02:24:37
Need help figuring out a couple common workflows with Github. I come from a VS TFS background, so forgive me. Undoing Pending Changes Let's say I have cloned of a git repository to my local file system. At this point, the project's local files match exactly what's in the remote repoistory. Then I decided to make some changes to the code, and change the local versions of a couple files. After doing some testing, I figure out that I want to discard my local changes and revert the local files back to what they are in the remote repoistory. How do I undo these local changes, restoring them to the

How to undo the last commit in git [duplicate]

╄→гoц情女王★ 提交于 2019-12-03 00:04:35
问题 This question already has answers here : How do I undo the most recent local commits in Git? (81 answers) Closed 3 years ago . By mistake, I did git add . and git commit in the develop branch. But luckily, I did not do git push . So I wanted to revert it back to original state. I tried git reset --soft and git reset HEAD --hard but looks like I have messed it up. How do I fix this? I want to go back to original state and possibly keep the code changes. 回答1: I think you haven't messed up yet.

Trouble pushing to origin after local hard reset

人盡茶涼 提交于 2019-12-02 09:59:10
I recently did a hard reset of my local git repository: In other words I reset it to an earlier point in time. Now when I try to push up to the origin it tells me that it can't because the origin contains work of a later date than my repository. This makes sense, but I don't care about the work the origin has after my local repository. If I first pull , which is what I am told to do, I presume that my local HEAD will then become whatever the origin HEAD was, i.e. with the additional work and my hard reset will be for nought. How should I proceed here? To recap, I don't care about the

git reset --merge vs git reset --keep [duplicate]

南楼画角 提交于 2019-12-01 02:51:15
This question already has an answer here: What are typical use cases of git-reset's --merge and --keep flags? 1 answer I have read the documentation , however I am having a hard time understanding the difference between git reset --merge And git reset --keep Please provide a simple explaination and/or example. I agree that the documentation is not very clear. From testing, I have found three differences, relating to what happens to files which: have staged changes no unstaged changes In summary: reset --merge always discards the index (staged changes); aborts if unstaged and staged changes

git reset --merge vs git reset --keep [duplicate]

a 夏天 提交于 2019-11-30 16:42:58
问题 This question already has an answer here : What are typical use cases of git-reset's --merge and --keep flags? (1 answer) Closed 3 years ago . I have read the documentation, however I am having a hard time understanding the difference between git reset --merge And git reset --keep Please provide a simple explaination and/or example. 回答1: I agree that the documentation is not very clear. From testing, I have found three differences, relating to what happens to files which: have staged changes

What is the difference between “git checkout — .” and “git reset HEAD --hard”?

匆匆过客 提交于 2019-11-30 12:21:11
问题 This is not a general question about what '--' does, as in the marked duplicate. This is a git-specific question asking for clarity on what the operational differences are between the mentioned commands. If I want to clean out my current directory without stashing or committing, I usually use these commands: git reset HEAD --hard git clean -fd A co-worker also mentioned using this command: git checkout -- . It's a difficult command to google, and it's not clear to me from the git

How I can store some local changes that survives git reset --hard

余生长醉 提交于 2019-11-30 04:56:58
问题 I have some local changes ( not in separate files so .gitignore doesn't work ) that I don't want to commit. I do git reset --hard sometimes after commit to clear occasional changes but obiously I also lose my useful changes that I want to leave. How I can keep my useful changes? 回答1: You can also try: git update-index --skip-worktree -- file # to cancel it: git update-index --no-skip-worktree -- file It should resist a git reset --hard . (see this answer on the ' -- ' double hyphen use) See

What is the difference between “git checkout — .” and “git reset HEAD --hard”?

会有一股神秘感。 提交于 2019-11-30 02:31:53
This is not a general question about what '--' does, as in the marked duplicate. This is a git-specific question asking for clarity on what the operational differences are between the mentioned commands. If I want to clean out my current directory without stashing or committing, I usually use these commands: git reset HEAD --hard git clean -fd A co-worker also mentioned using this command: git checkout -- . It's a difficult command to google, and it's not clear to me from the git documentation what this command actually does. It seems to be one of the later-mentioned usages in the manual. At a

git rm --cached file vs git reset file

ぐ巨炮叔叔 提交于 2019-11-29 19:51:06
I'm trying to learn Git. I'm confused between git rm --cached file and git reset file both of the commands seem to take the file from staged to un-staged area. How do the commands differ? git rm --cached <file> will completely remove the file's contents from the index. This means that on commit the file will be removed from the HEAD commit. (If the file was only added to the index and not yet tracked this is a "no-op".) git reset -- <file> resets the contents of the file in the index to be the same as the head commit. This means that on commit no changes will be committed to the file. This