git-reset

Git: How to reuse/retain commit messages after 'git reset'?

跟風遠走 提交于 2019-11-29 19:41:30
As Git user I regular come across the situation, that I need to rework one or more commits in a way which do not fit into --amend or rebase -i with fixup commits. Typically I would do something like git reset HEAD~1 # hack, fix, hack git commit -a # argh .. do I need to retype my message? I take sensible composed commit messages quite serious. They typically contain larger text with references & justifications for the change. Until now, I'm quite annoyed on the lengthy process to recover my old commit message via an unsorted git reflog , git log and copy & paste process. Is there a better to

What are typical use cases of git-reset's --merge and --keep flags?

痞子三分冷 提交于 2019-11-29 05:49:33
In a recent answer in which he details the typical use cases of git-reset 's three most commonly used options ( --hard , --mixed , and --soft ), torek mentions in passing that git-reset also offers two relatively esoteric flags, called --merge and --keep . The git-reset man page describes those two flags as follows: --merge Resets the index and updates the files in the working tree that are different between <commit> and HEAD, but keeps those which are different between the index and working tree (i.e. which have changes which have not been added). If a file that is different between <commit>

git rm --cached file vs git reset file

折月煮酒 提交于 2019-11-28 15:43:43
问题 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? 回答1: 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

Git: How to reuse/retain commit messages after 'git reset'?

白昼怎懂夜的黑 提交于 2019-11-28 15:13:56
问题 As Git user I regular come across the situation, that I need to rework one or more commits in a way which do not fit into --amend or rebase -i with fixup commits. Typically I would do something like git reset HEAD~1 # hack, fix, hack git commit -a # argh .. do I need to retype my message? I take sensible composed commit messages quite serious. They typically contain larger text with references & justifications for the change. Until now, I'm quite annoyed on the lengthy process to recover my

Reset all changes after last commit in git

折月煮酒 提交于 2019-11-28 14:55:37
How can I undo every change made to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files? First reset the changes git reset HEAD --hard then clean out everything untracked. If you want to keep files that are not tracked due to .gitignore , be careful with this command. git clean -fd How can I undo every change made to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files? You can undo changes to tracked files with: git reset HEAD --hard You can remove

How to squash/rebase in a single shot

a 夏天 提交于 2019-11-28 13:14:00
How can I, with minimum effort, squash all my commits (even with merges and conflict resolutions) to a single one on a feature branch and then rebase on top of the branch where I started developing from? Don't want to redo conflict resolution that's already done . Keep hassle to a minimum. Suppose the branches we are talking about are master and featureX. The simplest way I know is git checkout featureX git merge -m "Bring latest changes from master" master # magic starts here git reset --soft master # put featureX branch pointer on top of master tip # at this point all the changes related to

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

好久不见. 提交于 2019-11-28 04:13:52
$ 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. 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 for a path is what git reset -- <path> does. You can accomplishment what you're trying to do using git

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

只愿长相守 提交于 2019-11-28 03:17:49
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 if logged commit e6523efada4d75084e81971c4dc2aec621d45530 Author: Luca G. Soave <luca.soave@gmail.com>

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

╄→гoц情女王★ 提交于 2019-11-28 02:39:05
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 HEAD foo/bar.txt Unstaged changes after reset: M foo/bar.txt Now it is getting confusing: $ git status

“git rm --cached x” vs “git reset head --​ x”?

China☆狼群 提交于 2019-11-28 02:33:21
GitRef.org - Basic : git rm will remove entries from the staging area. This is a bit different from git reset HEAD which "unstages" files. By "unstage" I mean it reverts the staging area to what was there before we started modifying things. git rm on the other hand just kicks the file off the stage entirely, so that it's not included in the next commit snapshot, thereby effectively deleting it. By default, a git rm file will remove the file from the staging area entirely and also off your disk > (the working directory). To leave the file in the working directory, you can use git rm --cached .