Are these two commands really the same (reset --soft vs commit --amend)? Any reason to use one or the other in practical terms? And more importantly, are there any other uses for reset --soft apart from amending a commit?
git reset is all about moving HEAD, and generally the branch ref.
Question: what about the working tree and index?
When employed with --soft, moves HEAD, most often updating the branch ref, and only the HEAD.
This differs from commit --amend as:
When I decide to update both projects, I don't simply pull from projectA and projectB as that would create two commits for what should be an atomic update of the whole project.
Instead, I create a single merge commit which combines projectA, projectB and my local commits.
The tricky part here is that this is an octopus merge (three heads), but projectB needs to be merged with the subtree strategy. So this is what I do:
Here the author used a reset --hard, and then read-tree to restore what the first two merges had done to the working tree and index, but that is where reset --soft can help:
How do I redo those two merges, which have worked, i.e. my working tree and index are fine, but without having to record those two commits?
Also for your knowledge, if you have staged your changes already (ie with git add .) then you can reverse the staging by doing git reset --mixed HEAD or i've commonly also just used git reset
Note Again: You will need to make sure the branch you want to reset in the bare repo is the active branch. If not, follow VonC's answer on how to update the active branch in a bare repo when you have direct access to the repo.
You can use git reset --soft to change the version you want to have as parent for the changes you have in your index and working tree. The cases where this is useful are rare. Sometimes you might decide that the changes you have in your working tree should belong onto a different branch. Or you can use this as a simple way to collapse several commits into one (similar to squash/fold).
I use an IDE for development which has a good diff tool for showing changes (staged and unstaged) after my last commit. Now, most of my tasks involve multiple commits. For example, let's say I make 5 commits to complete a particular task. I use the diff tool in the IDE during every incremental commit from 1-5 to look at my changes from the last commit. I find it a very helpful way to review my changes before committing.
But at the end of my task, when I want to see all my changes together (from before 1st commit), to do a self code-review before making a pull request, I would only see the changes from my previous commit (after commit 4) and not changes from all the commits of my current task.
Please note that it seems like you 'went back' to your old commit but in fact, the amended commit is a new commit and has replaced that old commit A (you can check it's hash id by using git log), but in the end, you still have a nice commit history like you intended.
You can merge develop into next, but that can be messy sometimes, but you can also use git reset --soft origin/develop and create a commit with your changes and the branch is mergeable without conflicts and keep your changes.
It turns out that git reset --soft is a handy command. I personally use it a lot to squash commits that dont have "completed work" like "WIP" so when I open the pull request, all my commits are understandable.
A soft reset is a restart of a device, such as a smartphone, tablet, laptop or personal computer (PC). The action closes applications and clears any data in random access memory (RAM). Unsaved data in current use may be lost, but data stored on the hard drive, applications and settings are not affected.
On a Windows computer, a soft reset can be performed by clicking on the "Restart" button in the operating system, or by using the keyboard shortcut Ctrl+Alt+Delete. In a mobile device, a soft reset can be performed by holding down the power button for a few seconds, or by using a combination of buttons, such as the power button and the volume down button.
Soft resets are usually conducted in an attempt to fix malfunctioning applications or because they're required for software installation. Typically, this is triggered when an application stops responding, is running slowly or experiencing other software-related problems.
For example, if a user is experiencing problems with their computer, such as a frozen screen or unresponsive application, a soft reset can be used to restart the device without losing any data. A soft reset can be used to resolve the same problems with a mobile device.
A soft reset can also be used to resolve problems with network devices such as routers, switches and firewalls. For example, if a network device is not responding or is experiencing connectivity issues, a soft reset can be used to restart the device without losing any configuration or other data.
Another use case of a soft reset is in embedded systems, where the device is usually running on a real-time operating system and a soft reset is used to refresh the device without losing any data or configuration. For example, in a medical device, a soft reset can be used to refresh the device without losing any patient data or without affecting the device functionality.
It's important to note that a soft reset should not be used as a long-term solution to problems. If a device or system continues to experience problems after a soft reset, it may be necessary to perform a hard reset or to seek further technical assistance.
Is it possible to reset an arduino from the program? I was looking for something like reset() to simply re-start the program as-if you just pressed the reset button. I noticed it will reset every time you open the serial monitor, but cant find a way to do it myself.
How do I actually do that? Nothing I can find explains what the watchdog is, how it works, or how I would actually use it. everyone just says "use the watchdog".... not very helpful to someone that hasn't used it befor...
I found it a little hard to understand when I first read about it, perhaps it is just the way I learn. I rarely have a reason to reset from software, but every now and then there is a good reason to do so. Here is an example sketch that flashes an LED a few times, then waits one second, and reboots using the watchdog timer.
dmjlambert:
I found it a little hard to understand when I first read about it, perhaps it is just the way I learn. I rarely have a reason to reset from software, but every now and then there is a good reason to do so. Here is an example sketch that flashes an LED a few times, then waits one second, and reboots using the watchdog timer.
It has been a while so I would have to guess my reason was to do some experimentation with initiating a sketch upload without using DTR reset, perhaps from one Arduino to another. I'm sure there are a thousand various reasons to reset via software, and each reason could be individually picked apart. For example, I know I could just jump to the bootloader address instead of resetting. Sometimes a problem is only worth thinking about for a limited time. I'm not clear on the OP's reason. But I am sure there are multiple ways to accomplish whatever it is.
In the Arduino I imagine the most common reason is when someone writes an application and they want to include a command to enter the bootloader. They know the bootloader is the first thing to launch after reset, and even if they did know how to jump to it they shouldn't assume it was designed to run with the HW in any state but reset. Almost all of my "start the bootloader" commands are a reset instruction.
The only place that I have seen this be a problem is jumping to bootloaders with a peripheral enabled that the bootloader expected to be disabled due to RESET, but I've seen that many times now. I'll never jump to a bootloader ever, and in general you should never jump to code that wasn't built expecting for you to jump to it.
Theoretically, given pointer bugs and cosmic ray errors, you should never jump to re-init code unless you seriously did write all of the code necessary to imitate a RESET instruction. At that point, however, you might want to be asking yourself why you're writing all of that code to avoid using a single instruction.
You're overestimating the average skill level in this environment. Based on requests that I've seen in this forum in the time I've been around, the most common reason is to restart a game, or something elementary like that. The code I posted is intended to do that, in a safe, easy way. But I think that it should be simplified by putting the setup functions inline, like:
There is a simple way to reset the Arduino from a software view point.
You can view it at you tube Arduino Watch Dog tutorial. - YouTube
And you can download the library from GitHub - sodcore/WatchDogReset: Watch dog timer reset for arduino
Sometimes when a device will not connect to wifi for say 20 times, I put in a delay and then reset and start over. Sometimes it then connects. This stuff has gotten to a level of complication that nobody knows the whole story of everything about it.
A soft reset is also known as a force restart. A soft reset differs from a "normal" restart. The latter simply involves turning off your iPhone and turning it on again. You can restart your iPhone even if the buttons are broken.
Take note that a soft reset also differs from a hard reset. When you hard reset or factory reset your iPhone, the procedure erases your iPhone's data and restores your device to its blank, default state, as though you just bought it.
c80f0f1006