#GIT

Delete a commit from branch in Git

I sure that there is at least once time in the life of a programmer, they need to delete a commit in the history of a branch. So I write this post to share you the way to delete a commit from branch in Git.

My example is we have a git log tree as below:

And you are working on branh DEV, you need to remote “Commit C” from branch DEV. So you should use command git rebase -i

In there, “ea61baa” is the hash key of “Commit C”. After entering the command, a editor will be opened with the content below:

You have to remove line

After that, save it.

You are done, just re-check by git log command

You can see that “Commit C” now is not in branch dev.

GIT – Keep files when merge conflict

With Git, sometimes you need merge between branches.  For example, you need merge BranchB to BranchA. Almost cases, if it has conflicts, you will open the conflict file and merge it manually. But in some cases, you have to keep file at either BranchA or BranchB. Fortunatly, “git checkout” command with options will help you do that.

To merge between 2 local branches:

Or merge a remote branch to a local branch:

To keep the file that we own:

To keep the file that they own:

In case you have too many files conflicted, you can use the command below:

 

Vim install Vumdle

To read this article, you have to make sure that you know linux command and your machine was installed VIM, GIT.

Firstly, install vumdle plugin by command:

And then,you go to your home directory and look for .vimrc. Open it and add lines below

So now, you can open vim and type:

And waiting for all plugin that you put to .vimrc file is installed completely.

Done!!!

Writing shell script to deploy changed file via ftp

When you work with a cheap host, you just have FTP account to push your file to host. It will be terrible if you have to pull all changed file to host via FTP. Because you must answer many stupid question as “what files I was change?”, “Where files I was change?”, “What is ftp account?” …

0284ed8e-26be-11e4-a4aa-12313d044945-medium

So I think that it is better if you write a script to handle all task and help you answer all question. The way is posted the below will run well in linux environment.

Firstly, we need a script to upload file via FTP.  The script below requires CURL. You just need to change value of REMOTE_HOST, REMOTE_USER, REMOTE_PASSWD. It will work well.

After that, you write a script to list all file that needs to push to your FTP host. That script is similar to the script below.

With the script above, you need to provide 2 tag name, and script will check all file changes between them.  Finally, It calls fpt.sh script to push that files to FTP host.

You can see full source code in my Github: https://github.com/thanhson1085/git2ftp

Working with branch in GIT

A strong point in GIT is so flexible when working with branch. So now I will share some GIT commands that usually use when working with branch.

e5191b66-3127-11e4-a844-22000a98b2af-medium

You never know how strong you are until being strong is the ONLY option you have

 

In software development process, when your production was go live, you should create new branch for each issue. And after finishing a issue you should merge code carefully.

List all branch of repository (both local and remote)

Checkout code from a remote branch

Update code from all remote branch

Merge code between two branch

Merge specify commit to branch:

Create branch from previous comit

Checkout specify file from other branch:

 

How to GIT

As you know, with GIT,  you can setup a social network for developer. Everyone in everywhere can code your project, as long as they know how to use git.

How to push your change to remote

How to create new branch in local

How to switch branch

How to create new branch in remote

How to delete branch in local

How to delete branch in remote

How to merge 2 branches in remote

 

How to revert changes before add

How to remove file in remote

How to remove folder in remote

 

How to show git history

How to ‘undo’ git commit

How to ‘undo’ git add

How to ‘undo’ git push

How to add a tag

How to delete a tag in local

How to push a tag to remote

 

How to checkout to tag

How to delete a tag in remote

How to checkout a remote branch

How to edit a commit message

How to revert changes in local

How to list of file changes

How to pull a git branch from remote

How to ignore file locally

Move a tag