Sunday 12 February 2017

Basic git commands

http://gitref.org/basic/ 
 
Get an existing from the server for the first time
git clone git@example.com:repositoryname
See what's changed
git status
Check in locally
git commit -m "good description"
Push local commits to the server
git push
Get and merge updates from the server
git pull
Stage a file for the next local commit
git add file
Stage all files for the next local commit
git add .
Create a new local branch
git checkout - b branchname
Switch to a local branch
git checkout branchname
Overview of local branches
git branch
Delete a local branch
git branch -d branchname
Insert changes on the server before your local changes
git pull --rebase
Temporarily discard local changes
git stash
Re-apply stashed away changes
git stash apply
Re-apply stashed away changes an delete them from stack
git stash pop
Find out who wrote something
git blame filename
Restore a deleted file (notice the space before and after the dash)
git checkout - filename
https://makandracards.com/makandra/517-basic-git-commands



How to merge a specific commit in git

Scenario
You were working on a certain branch of a git repository, and you committed some changes to it. Then you realize, this particular commit should also go to another branch of the repository BUT you are not ready for a complete merge. Maybe this commit was meant for the other branch?
You want to merge this particular commit from the current branch to the other branch of your requirement.
Resolution
Merging a specific commit from one branch to another is pretty easy: use the git cherry-pickcommand. The syntax is: git cherry-pick <commit hash>.
First make a note of the commit hash using the git reflog or git log command.
Then, switch to the branch where you'd like to merge the commit and run git cherry-pick with the commit hash, as shown in the example below.
$ git cherry-pick d4d8e7c
Now you will have merged the specific commit from one branch to the other.

No comments:

Post a Comment