1, first look at the file of several workspaces: unstaged changes,staged changes,local repository,remote Repository.
Only two workspaces are shown in the picture: unstaged changes,staged changes, but when you click the Commit button, it will be submitted to the local repository (native Repository).
If you click on Push Branch, it will be submitted to the remote repository (remotes Repository). Here's how it works:
Select the local branch that you just submitted, for example, with the locally identifier, then right-click and select Push Branch. is submitted to the remote repository (remotes Repository).
2, you submit the document, found that the wrong, want to withdraw, how to do?
Where: Working area corresponds to the status of the Git plugin in Eclipse unstaged changes,staging area corresponds to the state of the Git plugin in Eclipse is staged changes, The latter two phases are the same as the Git plugin in eclipse.
The 4 stages are divided into 3 steps:
The first step-"Step two: Git Add." Put all the files into staging area.
Step Two--"step three: Git commit-m" comment ", where comment represents the comments submitted.
Step fourth: Git push pushes all files from the local repository into the remote repository.
Of course, the above 4 districts, entering each district after successful will produce a state, plus the most initial state, altogether is 5 states. Let's name these 5 states as follows:
Unmodified (origin): The state of a file downloaded from a git server, the original state
Modified (Modified): Working area
Staged (staged): Staging area
Submitted (Committed): Local Repository
Pushed (pushed): Remote Repository
Steps to undo the modification:
1) Check the changes
Having learned the basic concepts, let's talk about how to undo a mistake. First of all, we need to know how to check the 3 steps of each step to modify what, and then to determine whether there is a successful modification. Check that the modified level two commands are the same, all diff, except that the parameters are different.
Modified, not staged
Git diff
First, let's see if we simply saved the file in the browser, but we haven't done git add yet. Previously modified (Modified): Working area, how we check for changes. Let's just take a file and do the experiment:
We randomly added 4 numbers at the beginning of the file to 1234, save the file, then the document entered the modified state, but has not entered the staging area, we run Git diff, the result is as follows:
Diff--git A/index.md B/index.md
Index 73FF1BA: 1066758 100644
---a/index.md
+ + b/index.md
@@ -1,5 +1,5 @@
---
-layout:main
+1234layout:main
Color:black
---
The results of Git diff tell us which files have been modified.
Staged, uncommitted, or staged (staged): Staging area
git diff--cached
Now let's put the changes into staging area to see. Do git add first, and then run Git diff, and you'll see no results:
This shows git diff this command only checks the differences between our workspaces and staging area, and if we want to see the difference between staging area and the local repository, we need to add a parameter to Git diff--cached:
Diff--git A/index.md B/index.md
Index 73FF1BA: 1066758 100644
---a/index.md
+ + b/index.md
@@ -1,5 +1,5 @@
---
-layout:main
+1234layout:main
Color:black
---
The difference we see at this point is the difference between staging area and the local warehouse.
Submitted, not pushed, committed (Committed): Local Repository
git diff master Origin/master
Now, we're going to submit the changes from staging area to the local Repository, and look at the differences. Do git commit before executing git diff--cached, no difference, execute git diff master Origin/master, you can see the difference:
Here, Master is your local Repository, and Origin/master is your remote repository (Repository), master is the main branch, because we all work on the main branch, So both sides are master, and origin represents the remote.
2. Start undoing changes
After knowing how to check various modifications, we started to try various undo operations.
Modified, not staged, i.e. working area
If we just modified the file in the editor, but we haven't executed git add yet, this time our file is still in the workspace, and we have not entered the staging area, we can use:
Git checkout.
Or
git reset--hard
To undo the operation.
As you can see, after the git checkout has been executed, the changes have been revoked and git diff has no content.
A pair of antonyms git Add. is the opposite of git checkout. After the changes are made, if you want to take a step forward and let the changes go to staging area, git add is executed. If you want to take a step back and undo the changes just now, execute git checkout.
Staged, uncommitted, i.e. staging area
You have already executed git add, but have not yet executed git commit-m "comment". At this point you realize the error and want to undo it, you can perform:
git reset
Git checkout.
Or
git reset--hard
Git reset just returned the changes to git Add. The previous state, that is, the file itself is still in the modified non-staged state, if you want to return the unmodified state, you also need to perform git checkout.
Perhaps you have noticed that the above two steps can be done with the same command git reset--hard. Yes, it is this powerful command that can one step your changes completely to an unmodified state.
Submitted, not pushed, that is, local Repository
Your hands are too fast, you have both git add and git commit, and your code has entered your local repository, but you regret it. Don't worry, there's a way.
git reset--hard origin/master
Or this git reset--hard command, but this time one more parameter origin/master, as we have said above, Origin/master represents a remote repository, since you have contaminated your local warehouse, then take the code back from the remote repository.
Pushed, that is, remote Repository
Unfortunately, your hands are too fast, you git add, git commit, and git push, then your code has entered the remote repository. If you want to recover, fortunately, because your local warehouse and remote warehouse is equivalent, you just need to restore the local warehouse, and then force push to the remote repository:
git reset--hard HEAD
Git push-f
Summarize:
Revocation of the above 4 states we all use the same command git reset--hard, the first 2 states are used even exactly the same, so as long as the git reset--hard the use of this command, you never have to worry about committing errors.
This article then contributes other GIT commands:
git config
Git init
git clone
git add
Git commit
Git diff
git reset
git status
git rm
git log
Git show
git tag
Git branch
Git checkout
git merge
Git remote
git push
Git pull
Git stash
So, let's get started!
git config
Usage: git config-global user.name "[Name]"
Usage: git config-global user.email "[Email address]"
This command sets the author name and e-mail address to be used with the submission, respectively.
Git init
Usage: git init [repository name]
This command is used to start a new repository.
git clone
Usage: git clone [url]
This command is used to get the repository from an existing URL.
git add
Usage: git add [file]
This command adds a file to the staging area.
Usage: git add *
This command adds one or more to the staging area.
Git commit
Usage: git commit-m "[Type in the commit message]"
This command permanently records or snapshots files in the version history.
Usage: git commit-a
This command uses the git add command to submit all files you have added and to submit all files you have changed since then.
Git diff
Usage: GIT diff
This command displays the file differences that have not yet been staged.
Usage: git diff-staged
This command displays the difference between the file in the staging area and the current version.
Usage: GIT diff [First branch] [second branch]
This command shows the differences between the mentioned two branches.
git reset
Usage: git reset [file]
This command cancels the staging file, but it retains the contents of the file.
Usage: git reset [commit]
This command undoes all commits after the specified commit and retains the changes locally.
Usage: git reset-hard [commit]
This command discards all history records and returns the specified commit.
git status
Usage: git status
This command lists all files that must be submitted, including files that have been modified (unstaged changes, that is, working area) and files that have not been added to git tracking.
git rm
Usage: git rm [file]
This command removes the file from the working directory and deletes it in stages.
git log
Usage: git log
Use this command to list the version history of the current branch.
Usage: git log-follow [file]
This command lists the version history of the file, including the renaming of the file.
Git show
Usage: git show [commit]
This command displays metadata and content changes for the specified commit.
git tag
Usage: git Tag[commitid]
This command is used to provide a token for the specified submission.
Git branch
Usage: Git branch
This command lists all local branches in the current repository.
Usage: GIT branch [branch name]
This command creates a new branch.
Usage: git branch-d [branch name]
This command removes the feature branch.
Git checkout
Usage: git checkout [branch name]
This command is used to switch from one branch to another.
Usage: git checkout-b [branch name]
This command creates a new branch and switches to it.
git merge
Usage: git merge [branch name]
This command merges the history of the specified branch into the current branch.
Git remote
Usage: git remote add [variable name] [remote Server Link]
This command is used to connect the local repository to a remote server.
git push
Usage: git push [variable name] Master
This command sends committed changes to the master branch to the remote repository.
Usage: git push [variable name] [branch]
This command sends a branch commit to the remote repository.
Usage: git push-all [variable name]
This command pushes all branches to the remote repository.
Usage: git push [variable name]:[branch name]
This command deletes the branch on the remote repository.
Git pull
Usage: git pull [Repository Link]
This command extracts and merges changes from the remote server into your working directory.
Git stash
Usage: git stash save
This command temporarily stores all modified trace files.
Usage: git stash pop
This command restores the most recently hidden files.
Usage: git stash list
This command lists all stored change sets.
Usage: git stash drop
This command discards the most recently hidden changeset.
This article turns from:https://www.toutiao.com/a6586232599520215556/?tt_from=mobile_qq&utm_campaign=client_share& Timestamp=1533516837&app=news_article&utm_source=mobile_qq&iid=39062783162&utm_medium=toutiao_ android&group_id=6586232599520215556
https://www.toutiao.com/a6581719073296482823/?tt_from=mobile_qq&utm_campaign=client_share×tamp= 1532498727&app=news_article&utm_source=mobile_qq&iid=38958718850&utm_medium=toutiao_android
The Git plugin in Eclipse uses