Since asking my last question which turned out to be about rebasing with GIT, I have decided that I don't want to rebase at all. Instead I want to:
I do this currently by copying the files to a new directory and then copying them back in to a new branch (branched at the same point as my working branch), and then merging that into master
or wherever.
Is this just plain bad and why? More important: Is there a better/GIT way to do this? git rebase -i
forces me to merge (and pick, and squash).
If you have been lazily writing multiple vague commits, you can use git reset --soft <old-commit> to make your branch point to that old commit. And as we learned, Git will start by moving the branch pointer to it and stops right there. It won't modify the index or working directory.
You can modify the most recent commit in the same branch by running git commit –amend. This command is convenient for adding new or updated files to the previous commit. It is also a simple way to edit or add comments to the previous commit. Use git commit –amend to modify the most recent commit.
The Git commit process provides a point-in-time snapshot (PIT snapshot) of the version-controlled files at the time of every change. An administrator can roll back the code repository to a previous commit -- that point-in-time copy -- in several ways, depending on the end goal. One approach is the git reset command.
The easiest thing to do is a soft reset.
So checkout your topic branch:
git checkout -b topic master
work, work, work.
git commit
git commit
git commit
git commit
Happy with this, you can make a new single commit on top of master
git reset --soft master
git commit
Now merge to master (it will be a fast-forward) and tidy up the topic branch. (Note that you don't need to do this if you are prepared to remember or tag where master was and just work on master without branching, you could have just done git reset --soft old-master
and git commit
and you wouldn't need these last clean-up steps.)
git checkout master
git merge topic
git branch -d topic
You can also use git merge
with the --squash
option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With