Undoing a commit in git

When forgot something on a commit:

git reset –soft HEAD^ — move to the commit one before the HEAD.

undo the last commit and move everything from that commit back into staging.

git commit –amend -m « modify something and add it to the last commit »

git reset –hard HEAD^ -undo last commit and all changes

git reset –hard HEAD^^ – undo last two commits and all changes

 

 

 

Unstaging files in git

When staging files that I didn’t mean to stage:

(use git reset HEAD (file) … to unstage)

git reset HEAD filename

HEAD – the last commit on the current branch

The file has its modifications.

Reset the file to its last commit.

git checkout — filename

Notes #4 – Git vs SVN, git-flow

A comparison between Git and SVN. Git’s major features:

  • Git was designed to be fully distributed from the start, allowing each developer to have full local control
  • Git branches are simpler and less resource heavy than Subversion’s
  • Git branches carry their entire history
  • Branch merging is simpler and more automatic in Git.
  • Git is extremely fast. Since all operations (except for push and fetch) are local there is no network latency involved

git-flow – a successful git branching model

The main branches:

  • master – the main branch where the source code always reflects a production-ready state.
  • develop – the main branch where the source code always reflects the latest delivered development changes. The « integration branch » where any automatic nightly builds are build from.

Other branches, with a limited life time,  with a specific purpose, to aid parallel development:

  • feature  – it branches off from develop and it must merged back into develop. It exists as long as the feature is in development
  • release – it branches off from develop  and it must merged back int develop and master. Branch name convention: release-*. Use it for minor bug fixes and preparing meta-data for a release
  • hotfix – it branches off from master and must be merged back into develop and master. Branch naming convention: hotfix -*. Use it when you need to act immediately upon an undesired state of a live production version, when a critical bug in a production version must be resolved immediately.

Automate git branching workflow – use  git-flow library of git subcommands that helps automate some parts of the flow to make working with it a lot easier.

Issues with git-flow – The git-flow process is designed largely around the « release » but when you need to deploy regularly (every day), like GitHub does, a much simpler workflow is required.

 

Notes #3 – Career, developers, git

5 Essential Pieces of Career Advice No One Ever Told You

In my opinion the most important of all: Your boss matters more than your company. Having the right mentor is the real key. The second important advice is don’t use data to pick a job, just do what you enjoy doing and be great at it. Also, the technical skills will only get you so far. You will have to learn how to navigate the world of office politics.

What distracts developers

The survey surprised me: « unplanned worked », 24.9% of the votes and « only » 22.7% of votes, social media. Chatty coworkers, meetings, forums and reading/writing emails are other reasons.

Git Commands and Best Practices Cheat Sheet – Print this git cheat sheet!

Installing and configuring Git on Windows

To install Git on Windows there is an easy installer you can download from git-for-windows.github.io/. After completing the installation and accepting all the default settings there should be a new application called Git Bash which will help you using Git.
After the installation some basic configurations are required like your name and your email. These are important because Git needs to know who is the author of your commits.
Start Git Bash and type the following commands:

git config --global user.name "Marius Istudor"

git config --global user.email "[email protected]"

You can run these commands any time you want but once you have run them they will stick around between updates.

The tool git config lets us changing the configuration variables that controls how Git looks and operates. You can check the settings using the following command:

git config --list

You can check the value of a parameter by typing git config :

git config user.name

You can find more commands by typing help:

git config --help