git reset --hard HEAD^
Also gitx has a nice contextual menu to discard changes.
If you locally create a new branch and then try to pull or push, git will complain, since that branch does not exist remotely. To push a new branch test
, do this:
git push origin master:test
Q: We’d like to collaborate without polluting the master branch. How can I get an experimental branch to my collaborator?
To see somebody else’s branch, it must be:
Let’s look at those in detail.
1. To upload a branch that is not master, you can simply type
git push \--all
That will simply copy all your branches to the server. Similarly,
get fetch \--all
will download all branches.
2. Once you’ve got the branch on your computer, we can check it out. We could very simply type the following, though it isn’t advisable:
git checkout origin/try
It does check out the branch, but now if you change things, git won’t know on which branch to store modifications. Git knows these problems, and it’s going to complain:
You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is now at 3ed69fb... Merge branch 'master' of pinocchio.unibe.ch:group01
To avoid the warning and the attached problems, use a tracking branch. A tracking branch is local branch that is aware of its server counterpart. For example, master is a tracking branch. It knows that its corresponding remote branch is origin/master. So, just type this:
git branch \--track try origin/try git checkout try
And now you can work on try, commit, push back, and your collaborator will get the changes, all without having to pollute master.
git svn clone https://www.iam.unibe.ch/scg/svn_repos/Papers/DSL
This initializes a local Git repository linked to the Subversion repository. The first time it takes a while to pull in all the revisions from the server, but then you can do all work locally using the standard Git tools: diff between arbitrary versions, blame people, work with branches, revert changes, tag versions, browse the logs, etc.
Committing changes is local, as with normal Git. You can do that as often as you like. It does not touch the SVN repository.
git svn rebase
updates and merges changes from the SVN server (like "git pull") and
git svn dcommit
pushes back your changes (like "git push") to the SVN server as individual SVN commits. They claim in the documentation that it is totally transparent, SVN users do not see that you are using Git.
See: http://www.kernel.org/pub/software/scm/git/docs/git-svn.html
Links: