ReinH Git Workflow

I am using this workflow:

  • Is it possible to keep .gitignore files out of SVN?
  • What does ^{} mean in git?
  • How to pipe git clone
  • fatal: This operation must be run in a work tree
  • Maintaining a branch that syncing with upstream
  • Sub-directory into independent repository and later merge back into main repository
  • where he mentions: “First, and while in your master branch (git checkout master), pull in the most recent changes:
    git pull origin master
    This should never create a merge commit because we are never working directly in master.”

    Whoops, I just did. I accidentally committed a few changes to a couple of files to my master (vs my topic branch). I then realized my mistake – deleted my topic branch. Now I want to get rid of my committed changes (to the master), what is the right thing to do? I have not rebased yet or pushed my changes to repo, so it is all local.

    In essence, I want to pull down the latest version of the master code and just disregard everything I have done to my local master (which is really one commit).

  • Can gitconfig options be set conditionally?
  • Create a git branch from selected commits on another branch
  • Git: How to check if a local repo is up to date?
  • Get time of last commit for Git repository files via Python?
  • Exporting the change log from a commit on GitHub
  • How can I see the most recent tagged commits in my repository?
  • 2 Solutions collect form web for “ReinH Git Workflow”

    If you just want to throw it away, while you’re on your master branch:

    git reset --hard HEAD^

    This command will reset your master’s HEAD pointer to the previous commit. (You could also say “HEAD~1”, which means the same thing as HEAD^.) More generally, you can also reset your master to be the same as the server’s:

    git reset --hard origin/master

    This will work regardless of the state of master (i.e. 5 commits ahead of origin, or 30 commits behind it). The --hard option in these commands means that the files in your working tree will also be reset along with the branch heads.

    Extra tips

    If you were in a similar situation where you actually wanted to keep your changes, you can always do:

    git fetch             # This grabs changes from the server without merging them
    git rebase origin

    That will replay any work you have in master on top of the latest changes on the server.

    Yet another alternative would be to create a topic branch for your work on master:

    git checkout -b newfeature

    Then you could switch back to master (git checkout master) and use the first command I gave to rewind master back one commit. Remember, branches are really just convenient names for commits in your repository. For example, master is just a reference to the latest commit on that branch. You can move these references at will, and as you get more advanced with git, you’ll find yourself doing it fairly often.

    I also recommend you get in the habit of running gitk --all whenever you’re playing with branches, so you can visually see exactly what you’re doing. When I was new to git, I ran this command all the time. I still do…

    All your commits lost by the branch deletion are there yet in git.

    You can access all of them by traversing the reflog. Take a look to

    man git-reflog
    Git Baby is a git and github fan, let's start git clone.