How to push into master or any other branch after removing last n commits in git?

  1. git log to find out the commit you want to revert
  2. git push origin +daee17:master while daee17 is the commit before the wrongly pushed commit.+ was for force push
  3. Finally use git push origin master to sync your local with your git repo

And that’s it.

Below is my log aka example. One of the teammates had committed to the repo (he was not supposed to) after which I committed on server and when I tried to push it on github.com, I received REJECTED error because the remote contained 2 commits which the server did not have.

[ttc@aws www]$ git push origin master
To github.com:Organization/ttc.git
 ! [rejected]          master -> master (fetch first)
error: failed to push some refs to '[email protected]:Organization/ttc.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
[ttc@aws www]$ git history
git: 'history' is not a git command. See 'git --help'.
[ttc@aws www]$ git log
commit 8168d26efcd2cc9aa7ddaa47ce3c11d61a134813 (HEAD -> master)
Author: Your Name <[email protected]>
Date:   Mon Jan 21 18:57:55 2019 +0000

    filters css

commit daee17568269bb517870bba5aa75031dbd4f4554 (origin/master)
Author: Your Name <[email protected]>
Date:   Mon Jan 21 06:02:18 2019 +0000

    ravi shopyby resynced api and classes

commit 423c77c82bfb88d0febd5735bae3795740aa5b72
Author: Your Name <[email protected]>
Date:   Mon Jan 21 05:56:24 2019 +0000

    plugin defaulted and collapsible removed

commit bbd39f5a124261af64d015a55d5bd8ba9fdec94a
Author: Your Name <[email protected]>
Date:   Sun Jan 20 13:57:24 2019 +0000

    hirens new design layouts

commit 988524d8d3e90265977355ea738c262c7249a8e0
Author: Your Name <[email protected]>
Date:   Fri Jan 18 15:52:32 2019 +0000

    shubham landing page code improved

https://stackoverflow.com/a/35291514/2229148

How to setup / enable Directory index listing?

When a web browser is pointed to a directory on your website which does not have an index.html file in it, the files in that directory can be listed on a web page.

Directory Lister is a simple PHP script that lists the contents of any web-accessible directory and allows navigating therewithin. Simply upload Directory Lister to any directory and get immediate access to all files and sub-directories under that directory. Directory Lister is written in PHP and distributed under the MIT License.

http://www.directorylister.com

Directory Lister requires PHP 5.3+ to work properly. For more information on PHP, please visit http://www.php.net.

steps to set up directory listing:

  1. Open “public_html” and Upload “index.php” and “resources” folder.
  2. Now go to “resources” directory and rename “default.config.php” to “config.php”.
  3. Also, upload additional files to the same directory as index.php.
  4. All Done!!!

Enable / Disable directory index listing.

enable:

To have the web server produce a list of files for directories, use the below line in your .htaccess  (can be found in FTP -> public_html folder):

Options +Indexes

disable:

To have an error (403 – Forbidden) returned instead, use this line:

Options -Indexes

When enabled you can visit your website to see Directory listing.

Hope, this post was helpful.

Thank You.

Creating a table in PhpMyAdmin Xampp server.

Hello People.

In this post we will discuss that how you can create a table in phpmyadmin xampp server for your php project.

Before creating a table first you must create a database, because without database you can not create a table.

steps to create a table in phpmyadmin.

  • Start your Xampp server and open the following link in your browser.
    localhost/phpmyadmin . Now click on the New button.
  • Give name to your database and hit create button. As shown in the image below.

Our database has been created and now we can start creating the table.

  • Click on the database that you just created in the previous step. Then give name to your table and specify the number of columns under the structure menu.
  • Next you just need to fill your table with the details of your project.

You can also create table using MySql query. For that go to the SQL menu and and write your query. If your query is correct the table will be created. An example is shared below.

CREATE TABLE persons (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Address varchar(255),
    phone varchar(70) NOT NULL UNIQUE
);  

So, that’s all for now.

Thank You.

How to add color gradients in HTML text?

.gradient-text {
    background: linear-gradient(to bottom right,#f27990, #332b75);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

Live Example

5 ways to redirect your Web page?

Hi Everyone!

In this post we will be learning about redirects. And see how you can redirect your web-page.

We will see two ways to redirect web-pages:

  • Through your registrars’ Cpanel.
  • Right into your code.

Through cPanel redirect feature

You can easily redirect your visitors from one page to another with the help of the Redirects feature. 

To setup a redirection, access your website’s Control Panel and locate the Redirects menu.

In the Create a Redirect section. You can set up a redirection from one page of your website to another. This also works for subdomains or completely different websites.

If you choose to use HTTPS, make sure the redirected page has a certificate first, because redirecting to a website without an SSL certificate but using the HTTPS protocol for it, will most likely land your visitor to an error page

Now let’s see how you can set redirection by including few lines in your code.

HTML redirects:

The simplest way to redirect to another URL is with the Meta Refresh tag. We can place this meta tag inside the <head> at the top of any HTML page like this:

<meta http-equiv="refresh" content="0; URL='http://new-website.com'" />

JavaScript redirects

Redirecting to another URL with JavaScript is pretty easy, simply change the locationproperty on the window object:

// Use any of the following lines below.

window.location = "http://new-website.com";
window.location.href = "http://new-website.com";
window.location.assign("http://new-website.com");
window.location.replace("http://new-website.com");

Apache redirects

The most common method of redirecting a web page is through adding specific rules to a .htaccess file on an Apache web server.

Redirect 301 / http://www.new-website.com

PHP redirects

With PHP we can use the header function, which is quite straightforward:

<?php
  header('Location: http://www.new-website.com/', true, 301); // Permanent redirection.
// OR
  #header('Location: http://www.new-website.com/', true, 307); // Temporary redirection.
  exit();
?>

This is it for this post. Now the comment section is all yours.

Thank You.

Connection timeout with MySQL database.

MySQL disconnects automatically after some time.

If you experience MySQL timeouts, it could be due to heavy or very long MySQL queries.

You can try using mysql_reconnect command before every query, and it should be fine.

MySQL server timeout can occur for many reasons but most commonly it is caused by either an application bug, a network timeout issue, or due to the MySQL server restarting.

These steps could solve the issue. (By setting no time to MySQl.)

  • Edit your my.cnf (MySQL config file)
sudo nano /etc/mysql/my.cnf

  • Add the timeout configuration and adjust it to fit your server.
wait_timeout = 28800
interactive_timeout = 28800
  • Save the changes (CTRL + X , Y , ENTER)
  • Restart MySQL
sudo service mysql restart

The new changes will be applied once it restarts. Hope this will help you.

Thank You.

How to hide a specific category from Google Index in Magento 2?

In Magento Admin Panel, Go to Catalog in Left Menu > Categories
Select the category you want to edit and in Design Section > Layout Update XML, put this value:

<head>
    <meta name="robots" content="NOINDEX,NOFOLLOW"/>
</head>
How to add noindex nofollow on specific category page in Magento2

Save the category and then Clear the cache

ReactJS: Create your first react app.

React is one of the most in-demand and popular JavaScript library. And the reason is simple it gives you the ability to create complex User Interfaces with minimal and simplified code.

In this article we are going to go through the installation process and the process of creating your first react app.

Creating a react js app.

There are a few different ways of creating a react app. But the simplest way is using a CDN – link. This allows you to start using ReactJS instantly, without any installation setup.

Just include these two lines in your HTML file.

<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

But this is not the best way of creating a react app. The best way to create a react app is Using react CLI, but for that, you need to have NodeJS installed.

Once NodeJS is installed in your system. Now there are two ways of creating react app.

The Quick way (npx):

Use the following command in your preffered terminal.

npx create-react-app <app-name>
cd <app-name>
npm start

The first line will create a react app and name it. And the third line will open the app in your default browser. Which looks something like this.

The productive way (NPm):

In this way first we will install NPM (Node package manager) then will create the react app.

That’s why i call this way as the productive way, because soon or late you would have to install NPM then why not now.

Follow these command below.

npm install -g
cd <app-name>
npm start

The first line installs npm globally. And you know what the next two line does.

Actually we can also create a react app via yarn. But we are just not gonna get into it in this post.

So, i hope this was helpful to you.

Thank You.

How to learn Git in 15 minutes? List of most basic git commands

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git is easy to learn and has a tiny footprint with lightning fast performance. Every dev has a working copy of the code and full change history on their local machine

Here are some most important and useful GIT commands that will surely help you.

Git Commands:

  • This command sets the author name and email address respectively to be used with your commits.
$ git config –global user.name "[name]" 
$ git config –global user.email "[email address]"
  • This command is used to start new repository.
$ git init [repository name]
  • This command is used to obtain a repository from an existing URL.
$ git clone [url]  
  • This command records or snapshots the file permanently in the version history.
$ git commit -m "[Type in the commit message]"
  • This command lists all the files that have to be committed.
$ git status 
  • This command shows the metadata and content changes of the specified commit.
$ git show [commit]
  • These commands lists, creates and delete branch respectively.
$ git branch  
$ git branch [branch name]  
$ git branch -d [branch name]  
  • This command is used to connect your local repository to the remote server.
$ git remote add [variable name] [Remote Repo Link]  

  • This command sends the committed changes of master branch to your remote repository.
$ git push [variable name] master  
  • This command sends the branch commits to your remote repository.
$ git push [variable name] [branch]
  • This command pushes all branches to your remote repository.
$ git push –all [variable name]
  • This command deletes a branch on your remote repository.
$ git push [variable name] :[branch name]
  • This command fetches and merges changes on the remote server to your working directory
$ git pull [Repository Link]

If you want more commands with examples, please let us know in the comments below.

More Useful commands:

  • Checks if sha is in production.
$ git tag --contains [sha]
  • Number of commits by author.
$ git shortlog -s --author 'Author Name'
  • List of authors and commits to repository sorted alphabetically.
$ git shortlog -s -n
  • See differences in file before committing / compare recently edited file with its last committed state
$ git diff path/to/file.txt
  • Undo local changes to a file.
$ git checkout -- filename
  • Undo/revert last commit
git revert HEAD^
  • Remove last commit from history (WITHOUT keeping changes)
$ git reset --hard HEAD~
  • Remove last commit from history (WITH keeping changes)
$ git reset HEAD~
  • Shows number of lines added or removed from repository by an author since some time in the past.
$ git log --author="Author name" --pretty=tformat: --numstat --since=month | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }'

referenceS:

https://gist.github.com/davfre/8313299#undoing-previous-actions

https://stackoverflow.com/questions/8903953/how-to-revert-last-commit-and-remove-it-from-history

https://github.com/bpassos/git-commands#committing-files

How to edit default python version for a linux user?

Edit the bash profile and add an alias using the following code

$ nano ~/.bashrc

Put the following line of code in .bashrc file and alter the python3.6 path as per your new installation

alias python='/usr/local/bin/python3.6'

Use CTRL x to exit and save
After that you need to reload the source, so use the following command and you are good to go.

$ source ~/.bashrc