git-reset

Why git can't do hard/soft resets by path?

柔情痞子 提交于 2020-01-09 08:37:08
问题 $ git reset -- <file_path> can reset by path. However, $ git reset (--hard|--soft) <file_path> will report an error like below: Cannot do hard|soft reset with paths. 回答1: Because there's no point (other commands provide that functionality already), and it reduces the potential for doing the wrong thing by accident. A "hard reset" for a path is just done with git checkout HEAD -- <path> (checking out the existing version of the file). A soft reset for a path doesn't make sense. A mixed reset

Move commits from master onto a branch using git

余生颓废 提交于 2020-01-09 06:04:30
问题 I'm trying to learn how to use Git effectively and I'm wondering how I should (good practice/bad practice?) solve the following case: Say I have the following chain of commits in master: Initial commit Commit 1 Commit 2 Commit 3 Then I realize that what's done in the last two commits is completely wrong and I need to start from Commit 1 again. Questions: How should I do that? Can I move Commit 2 and 3 to a separate branch to keep for future reference (say they weren't that bad after all) and

Unstaged changes left after git reset --hard

僤鯓⒐⒋嵵緔 提交于 2020-01-08 17:21:52
问题 The title says it all. After git reset --hard , git status gives me files within the Changes not staged for commit: section. I've also tried git reset . , git checkout -- . and git checkout-index -f -a , to no avail. So, how can I get rid of those unstaged changes? This seems to hit only Visual Studio project files. Weird. See this paste: http://pastebin.com/eFZwPn9Z. What is special with those files, is that in .gitattributes I have: *.sln eol=crlf *.vcproj eol=crlf *.vcxproj* eol=crlf Also,

Trouble pushing to origin after local hard reset

帅比萌擦擦* 提交于 2019-12-31 05:22:27
问题 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

After reset --hard all my untracked files are gone

為{幸葍}努か 提交于 2019-12-24 08:43:55
问题 I did a git hard reset without committing my files. After firing reset I checked all my untracked files are gone. I am expecting it will affect only the changes we made during the commit and it will simply reset those changes. But I was wrong. Is there any way to get recover all my untracked files ? Any Help would be really really appreciated. Thanks 回答1: If you previously did a git add with your untracked files, then git reset --hard will delete them. Git has no process of restoring these

unable to commit a file, accidentally renamed with mv

≯℡__Kan透↙ 提交于 2019-12-23 01:12:33
问题 I've accidentally used mv to rename a file which was under git. I renamed the file from lower case to uppercase keeping the name same. mv abc.java ABC.java I've also made changes and committed the file after that . How do I now make an actual git rename of this file? Git bash doesn't seem to understand the difference between ABC.java and abc.java. I'm not sure what changed on master(by others) but after moving to a branch, I'm no more able to commit my changes to the file. It says the old

What is difference between 'git reset --hard HEAD~1' and 'git reset --soft HEAD~1'?

前提是你 提交于 2019-12-20 08:27:23
问题 I tried to undo my commit in git. Is it dangerous to use git reset --hard HEAD~1 ? What is the difference between different options for git reset ? 回答1: git reset does know five "modes": soft, mixed, hard, merge and keep. I will start with the first three, since these are the modes you'll usually encounter. After that you'll find a nice little a bonus, so stay tuned. soft When using git reset --soft HEAD~1 you will remove the last commit from the current branch, but the file changes will stay

I need to pop up and trash away a “middle” commit in my master branch. How can I do it?

梦想的初衷 提交于 2019-12-17 17:26:30
问题 For example, in the following master branch, I need to trash just the commit af5c7bf16e6f04321f966b4231371b21475bc4da, which is the second due to previous rebase: commit 60b413512e616997c8b929012cf9ca56bf5c9113 Author: Luca G. Soave <luca.soave@gmail.com> Date: Tue Apr 12 23:50:15 2011 +0200 add generic config/initializers/omniauth.example.rb commit af5c7bf16e6f04321f966b4231371b21475bc4da Author: Luca G. Soave <luca.soave@gmail.com> Date: Fri Apr 22 00:15:50 2011 +0200 show github user info

Git: can't undo local changes (error: path … is unmerged)

两盒软妹~` 提交于 2019-12-17 17:18:53
问题 I have following working tree state $ git status foo/bar.txt # On branch master # Unmerged paths: # (use "git reset HEAD <file>..." to unstage) # (use "git add/rm <file>..." as appropriate to mark resolution) # # deleted by us: foo/bar.txt # no changes added to commit (use "git add" and/or "git commit -a") File foo/bar.txt is there and I want to get it to the "unchanged state" again (similar to 'svn revert'): $ git checkout HEAD foo/bar.txt error: path 'foo/bar.txt' is unmerged $ git reset

How to uncommit my last commit in Git [duplicate]

你。 提交于 2019-12-17 17:18:01
问题 This question already has answers here : How do I undo the most recent local commits in Git? (81 answers) Closed 3 years ago . How can I uncommit my last commit in git? Is it git reset --hard HEAD or git reset --hard HEAD^ ? 回答1: If you aren't totally sure what you mean by "uncommit" and don't know if you want to use git reset , please see "Revert to a previous Git commit". If you're trying to understand git reset better, please see "Can you explain what "git reset" does in plain English?".