git lesson please
rlaager at wiktel.com
Wed Dec 13 08:25:21 UTC 2017
On 12/13/2017 12:25 AM, Hal Murray via devel wrote:
> Is there a simple way to do a git pull when I have edits in progress?
Use `git stash`, which (as you put it) is the "better way" to "save them
off to the side".
# Choose *one*:
git stash apply
git stash pop
`git stash apply` leaves the stashed state in the stash list. `git stash
pop` deletes it from the stash list, if and only if applying it was
> Correspondingly, if I commit some changes, then discover a better way, is
> there a simple way to undo a commit?
See below for some specifics, but I'm going to answer this more
`git rebase` allows history editing. This is my typical recipe, which
does an interactive rebase of all changes since upstream HEAD:
git rebase -i origin/master
In there, you can specify what to do with each commit. If you delete one
from the list, it will be deleted from the history. If you re-order
them, the commits will be re-ordered. You can squash them together, stop
for editing, or reword messages.
> I think revert applies another commit
> that undoes the edit, but that leaves cruft in the log.
You have this correct. You can use rebase to squash them together, if
that makes sense in a particular situation.
If you don't need to fully undo it, just make a new commit and then
squash them together with `git rebase`.
> Is there an
> option/command for the special case where the commit I want to undo is the
> last one?
If you want to modify, which is a more common case for me than "undo":
git commit --amend
If you want to blow it away completely AND roll back your working tree:
# DANGEROUS; read the above line carefully:
git reset --hard HEAD^
While I haven't reviewed it, I found the following in a Google search,
and you might find it helpful:
More information about the devel