git lesson please
Stromeko at nexgo.de
Wed Dec 13 18:00:02 UTC 2017
Hal Murray via devel writes:
> Is there a simple way to do a git pull when I have edits in progress?
Yes, as Git tries to tell you already:
> [murray at hgm raw]$ git pull
> error: cannot pull with rebase: You have unstaged changes.
> error: please commit or stash them.
So you either commit your changes, then pull (maybe with rebase so your
commit goes on top of the HEAD you're pulling) or you stash, which
basically does a commit, then resets HEAD to before said commit (with
the stashed work set aside so you can apply it again).
> I can commit them, but I'd like to do more testing first. I expect all the
> files I've edited don't conflict with any recent changes. I could save them
> off to the side, checkout to make git happy, git pull, then restore the saved
> copies. There must be a better way.
With Git, you'd better commit in this case. You can always go back and
clean up your commits later if you feel it's necessary as long as you
haven't published those commits. I usually work on a branch named
"local" that gets rebased onto master automatically.
> Correspondingly, if I commit some changes, then discover a better way, is
> there a simple way to undo a commit? I think revert applies another commit
> that undoes the edit, but that leaves cruft in the log. Is there an
> option/command for the special case where the commit I want to undo is the
> last one?
There are several ways, some of them slightly dangerous. Git does not
really throw away any commits until they become unreachable and gc
cleans up. To prevent things becoming unreachable I would always put a
new branch on whatever HEAD I'm trying to leave behind. Once you are
satisfied that you got everything right, you can delete the branch.
I recommend to set aside a few hours to practise these potentially
destructive steps with a throwaway repo clone. Do some nonsense
commits, back them out, recover a lost HEAD from reflog etc. Really,
try to break things and then work your way out of that breakage until
you feel comfortable. There's much less chance you'll be in panic mode
encountering some unexpected breakage (which really is a question of
when, not if).
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+
More information about the devel