Whats the difference between git reset --mixed, --soft, and --hard?
2017-06-22 18:17
525 查看
https://stackoverflow.com/questions/3528245/whats-the-difference-between-git-reset-mixed-soft-and-hard
When you modify a file in your repository, the change is initially unstaged. In order to commit it, you must stage it—that is, add it to the index—using
When we run
Okay, so starting from here again:
Now let's do
And finally,
When you modify a file in your repository, the change is initially unstaged. In order to commit it, you must stage it—that is, add it to the index—using
git add. When you make a commit, the changes that are committed are those that have been added to the index.
git resetchanges, at minimum, where the current branch (
HEAD) is pointing. The difference between
--mixedand
--softis whether or not your index is also modified. So, if we're on branch
masterwith this series of commits:
- A - B - C (master)
HEADpoints to
Cand the index matches
C.
When we run
git reset --soft B,
master(and thus
HEAD) now points to
B, but the index still has the changes from
C;
git statuswill show them as staged. So if we run
git commitat this point, we'll get a new commit with the same changes as
C.
Okay, so starting from here again:
- A - B - C (master)
Now let's do
git reset --mixed B. (Note:
--mixedis the default option). Once again,
masterand
HEADpoint to B, but this time the index is also modified to match
B. If we run
git commitat this point, nothing will happen since the index matches
HEAD. We still have the changes in the working directory, but since they're not in the index,
git statusshows them as unstaged. To commit them, you would
git addand then commit as usual.
And finally,
--hardis the same as
--mixed(it changes your
HEADand index), except that
--hardalso modifies your working directory. If we're at
Cand run
git reset --hard B, then the changes added in
C, as well as any uncommitted changes you have, will be removed, and the files in your working copy will match commit
B. Since you can permanently lose changes this way, you should always run
git statusbefore doing a hard reset to make sure your working directory is clean or that you're okay with losing your uncommitted changes.
相关文章推荐
- What is the difference between symbolic link and hard link?
- What's the difference between “Normal Reload”, “Hard Reload”, and “Empty Cache and Hard Reload” in c
- What is the difference between a soft reference and a weak reference in Java?
- Q & A: The difference between hard and soft links
- The difference between hard and soft links
- what is the difference between little-endian and big-endian.
- What is the difference between Binding and TemplateBinding?
- php中each和print的区别(What is the difference between echo and print?)
- What are the difference between DDL, DML and DCL commands?
- The different between Soft link and Hard link
- overload与override的区别 What is the difference between overload and override
- 进程与线程的区别 What is the difference between process and thread
- What are the difference between DDL, DML and DCL commands?
- What is the difference between tag and branch-id?
- what is the difference between the setTimeout and setInterval
- What are the difference between DDL, DML and DCL commands[转]
- What is the difference between SLC and MLC?
- What is the Differences Between Sleep/Standby and Hibernate
- macro与inline的区别 What is the difference between macro and inline?
- What are the difference between DDL, DML and DCL commands?