$ git reset --hard HEADThis will throw away any changes you may have added to the git index and as well as any outstanding changes you have in your working tree.
If git reset takes a commit name as its parameter, it sets the current head to the specified commit and optionally resets the index and working tree to match. It defaults to HEAD (a keyword that refers to the most recent commit to the branch you're in).
Use --soft option when you want to stage all the previous commits but not commit them. This gives you a chance to modify the previous commit by adding to or taking away from it.
With --hard, it removes the commit from your repository and from your working tree. It's the equivalent of a delete button on your repository with no "undo". It's like the commit never happened, so it should be used with care.
2. Fixing commits
$ git commit --amend -C HEADThis amends the previous commit, and keeps the same log message. "-C commit" takes an existing commit object, and reuses the log message and the authorship information when creating the commit.
3. Reset and checkout
$ git reset [commit] [--] pathWith a path parameter, git reset resets the index entries for all paths to their state at [commit]. (It does not affect the working tree, nor the current branch.)
This means that git reset paths is the opposite of git add paths.
After running git reset paths to update the index entry, you can use git-checkout(1) to check the contents out of the index to the working tree. Alternatively, using git-checkout(1) and specifying a commit, you can copy the contents of a path out of a commit to the index and to the working tree in one go.
So generally, use git checkout paths to revert changes in the working tree and use git reset paths to unstage changes.
A good explanation of
reset
and, its difference with checkout
is here.
4. Tracking remote branch
Tracking when creating a new branch:
The full syntax is:
$ git checkout -track -b [local branch] [remote]/[tracked branch]Simpler version is:
$ git checkout -t origin/branchSetting up tracking for an existing branch:
& git branch --set-upstream branch upstream/branch
No comments :
Post a Comment