Reputation: 15698
I have a Visual Studio project that uses git. In the Team Explore>Changes window, I have a series of changes in the "Staged Changes" region. The problem is that these old, staged changes are no longer compatible with the work that is done in the "Changes" area.
from the "Staged Changes" area, Visual Studio only gives me an option to Unstage, which will merge the Staged Changes into the other change set. However, this isn't what I want to do.
How can I throw out all of the Staged Changes but keep all of the Changes, before I commit? Alternatively, how can I commit just the changes in the "Changes" set, without commiting what's in staging? If I can do that, I can delete what's in staging after my commit.
Upvotes: 1
Views: 6529
Reputation: 1506
The Changes page behavior when unstaging a staged change to a file depends on whether the file also has workdir-only changes to it.
If a file has only staged changes, unstaging it will remove those changes from the index but leave the file with the content in the workdir version. You can then select that same file and undo the workdir changes to get back to the last committed version of the file content.
If a file has both staged and workdir changes, unstaging the file will discard the index (staged) version and just keep the workdir version of the file.
Hope this helps.
Upvotes: 2
Reputation: 300
I guess you are mentioning same branch commits here. So you have local changes committed locally which were never pushed to . Now remote
has some updates on this branch which you want to update without losing your commits locally.
Example: if current branch is featureA
where you have staged changes
locally and featureA <remote>
has updates you want to merge in without losing your code changes locally.
If that was the case, create another branch on top of the current branch in your local.
git checkout -b featureB
So, featureB
has all commits you made locally on featureA
branch.
Now git checkout featureA
git reset --hard origin/featureA
NOTE: this will reset your local featureA
to match the remote
. So it deletes the local commit changes on this branch featureA
but, featureB
will be untouched.
Now in future you can checkout to featureB
any time in your local and you have your changes there.
If you want any of those commits back to be used in future into featureA
use cherry-pick
git cherry-pick <commit-hash>
This will create a commit on featureA
which ever commit-hash you have mentioned. If you have n
commit-hashes to implement from feartureB
. Do this for all n
commits on featureA
Upvotes: 0