FAQ – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Sat, 30 Jul 2022 22:51:52 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How to Git Remove File but Keep Local Version https://tecadmin.net/git-remove-file-but-keep-local/ https://tecadmin.net/git-remove-file-but-keep-local/#respond Mon, 09 Aug 2021 07:10:02 +0000 https://tecadmin.net/?p=28074 In a scenario where you are working with an application which files contain some sensitive data, you most likely don’t want to push code to a remote repository. The best practice, in that case, is to remove the file from the git. You are in the right place In case that you want to keep [...]

The post How to Git Remove File but Keep Local Version appeared first on TecAdmin.

]]>
In a scenario where you are working with an application which files contain some sensitive data, you most likely don’t want to push code to a remote repository. The best practice, in that case, is to remove the file from the git. You are in the right place In case that you want to keep the file locally. In this tutorial, you will learn how to git remove files but keep the local versions.

Git Remove File – Keep Local Version

  • In a situation where the file hasn’t been committed or pushed to a remote repository, use the command below.
    git reset {fileName} 
    
  • If the file has already been committed or pushed to a remote repository, tracking for it can be removed. In that case, your command will look like this.
    git rm --cached {fileName} 
    

Git Remove Directory – Keep Local Version

What about the directory removal? You’ll use pretty much the same syntax. The only difference is that you will append it with the -r option. Here’s an example

git rm --cached -r {directoryName} 

Keep in mind that in both cases terms within brackets have to be changed with the actual file or directory name that you want to remove.

Now here’s one useful trick. Even though you removed the file or directory with the commands above, Git will still try to track it. Additionally, if you accidentally commit or push that certain file or directory in the future, it will end up in a remote repository again. To avoid that, add the full path to the file/dir in question to the .gitignore file. That way you’ll make sure that it won’t end up in the remote repo again one way or another.

And we’ll wrap up this tutorial with that information. Put what you learned about git remove file but keep local to good use when you are dealing with sensitive information in your repositories. Security and data sensitivity are both very important!

The post How to Git Remove File but Keep Local Version appeared first on TecAdmin.

]]>
https://tecadmin.net/git-remove-file-but-keep-local/feed/ 0
How to Move a Directory to New Git Repository with Commit History https://tecadmin.net/how-to-move-a-directory-to-new-git-repository/ https://tecadmin.net/how-to-move-a-directory-to-new-git-repository/#respond Thu, 03 Jun 2021 17:24:59 +0000 https://tecadmin.net/?p=26464 Working with a Git repository, you may be required to move a specific directory to a new repository. If you just copy the directory content from one repository to another repository, you will lose the commit history. So follow this tutorial to remove a directory to a new Git repository with preserving the commit history. [...]

The post How to Move a Directory to New Git Repository with Commit History appeared first on TecAdmin.

]]>
Working with a Git repository, you may be required to move a specific directory to a new repository. If you just copy the directory content from one repository to another repository, you will lose the commit history. So follow this tutorial to remove a directory to a new Git repository with preserving the commit history.

In this tutorial, you will learn to move a directory from a Git repository to a new Git repository.

Move Directory to a New Git Repository

Follow the below steps to move a folder from an existing repository to a new repository.

  1. First of all, clone the main repository that contains a directory to move.
    git clone https://github.com/USERNAME/PRIMARY-REPO.git 
    
  2. Change directory to the newly cloned repository
    cd REPOSITORY-NAME
    
  3. Next, the filter-branch option lets you rewrite Git revision history by rewriting the branches mentioned in the command line. This will filter the subdirectory from the rest of the files in the current repository.
    git filter-branch --prune-empty --subdirectory-filter SUB_DIRECTORY_NAME BRANCH_NAME 
    

    Here:

    • SUB_DIRECTORY_NAME: The relative path to the directory within the project files, you need to separate from others.
    • BRANCH_NAME: Select the branch name from which the directory will be filtered, like “main”, “master”, “develop” etc.

    Once the above command executed successfully, you will see that the current directory has only files that were in the subdirectory.

  4. Create a new repository on GitHub, Gitlab, or any other Git providers.
  5. Set the new URL as the origin of the current directory. This is the same directory where you have filtered code from the previous git repository.
    git remote set-url origin https://github.com/USERNAME/NEW_REPO_NAME.git 
    
  6. Next, verify that the Git origin URLs have been updated in the current directory.
    git remote -v 
    

    You will see the following output:

    # Verify new remote URL
    > origin  https://github.com/USERNAME/NEW_REPO_NAME.git (fetch)
    > origin  https://github.com/USERNAME/NEW_REPO_NAME.git (push)
    
  7. Finally, Push all the files to the new repository.
    git push -u origin BRANCH_NAME 
    

Congratulations, You have successfully copied a directory to a new Git repository.

The post How to Move a Directory to New Git Repository with Commit History appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-move-a-directory-to-new-git-repository/feed/ 0
(Resolved) Unknown collation: utf8mb4_0900_ai_ci https://tecadmin.net/resolved-unknown-collation-utf8mb4_0900_ai_ci/ https://tecadmin.net/resolved-unknown-collation-utf8mb4_0900_ai_ci/#comments Mon, 10 May 2021 03:22:27 +0000 https://tecadmin.net/?p=25452 A collation is a set of rules that defines how to compare and sort character strings in a database server. In this tutorial, we are discussing an error faced during database restoration on another server. Let’s see the problem and solution to the issue faced recently: Problem During the migration of a web application, I [...]

The post (Resolved) Unknown collation: utf8mb4_0900_ai_ci appeared first on TecAdmin.

]]>
A collation is a set of rules that defines how to compare and sort character strings in a database server. In this tutorial, we are discussing an error faced during database restoration on another server.

Let’s see the problem and solution to the issue faced recently:

Problem

During the migration of a web application, I got the below error while restoring a database on another server. The collation id may differ based on the MySQL version.

Error message:

Error 1273 (HY000) at line 25 Unknown collation: 'utf8mb4_0900_ai_ci'

See the error screenshot during database restoration.

Error 1273 (HY000) Unknown collation: 'utf8mb4_0900_ai_ci'

Here you go with a solution.

Solution

After a little investigation, I found that the MySQL server running on the destination is an older version than the source. So we got that the destination server doesn’t contain the required database collation.

Then we do a little tweak in the backup file to resolve this. Edit the database backup file in text editor and replace “utf8mb4_0900_ai_ci” with “utf8mb4_general_ci” and “CHARSET=utf8mb4” with “CHARSET=utf8“.

Replace the below string:

ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

with:

ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

Save your file and restore the database.

The Linux system users can use the sed command to replace text in files directly.

sed -i 's/utf8mb4_0900_ai_ci/utf8_general_ci/g' backup.sql  
sed -i 's/CHARSET=utf8mb4/CHARSET=utf8/g' backup.sql  

That it. after the above changes, the database was successfully restored!

Hope this is solution helped you to resolve “Unknown collation: ‘utf8mb4_0900_ai_ci’” issue.

The post (Resolved) Unknown collation: utf8mb4_0900_ai_ci appeared first on TecAdmin.

]]>
https://tecadmin.net/resolved-unknown-collation-utf8mb4_0900_ai_ci/feed/ 22