Яндекс.Метрика
qr-код - Как-то так стрелка - Как-то так
Leading Economist + ... пиктограмма - Как-то Так THIS     Economic literacy and web solutions
All on the topic: what, how and why. Actual things - in their own words.
Turn your quality WITH ME - BUTW !
If you don't like what you get, change what you give. © Carlos Castaneda     KAKTOTAK.BY - economic design and web development services (php/js - telegram, WordPress, Laravel, Vue, SEO)    Cooperation - on an ongoing basis    Be in the topic   -    SUBSCRIBE      My notes are ECONOMICS +  и  WEB Developer's Guide | php+js+seo   в Telegram   telegram  

Git in Visual Studio Code: creating copies of the project and returning to them

If you have ever lost important changes in your project or faced the need to revert to a previous version of the code, you are familiar with all the delights of the headache associated with this.

Previously, many developers had to manually create copies of their projects and manage versions by uploading the project folder to a local server. It was time-consuming and time-consuming. However, with the advent of Git, this problem is solved in a few simple steps.

Git is a great tool that allows you to track all changes in a project and easily revert to any version of it without creating copies directly.

We have a task ahead of us: we are developing a project in Visual Studio Code and periodically need to create copies of the entire project. We also have a need to go back to a certain version of the project and continue working with it. How can I implement this task on a local system using Git?

The steps for working with Git in a project are to create copies of versions and return to them if necessary

Pre-installation of Git:

Before we start, let's make sure that Git is installed on our system. We can download it from the official website git-scm.com and follow the installation instructions for our operating system.

Initializing Git:

Let's open the terminal in VSCode in the folder of our project. Initializing a new Git repository:

git init

Adding Files:

Let's create several files in our project folder (for example, index.html , style.css and script.js ). Let's add these files to the index:

git add .

Commit changes:

Let's fix the changes with a message:

git commit -m "Initial version of the project"

Working on the project:

Let's make changes to our files. For example, let's change the text in index.html .

Creating a new commit:

Let's save the changes:

git add .
git commit -m "Changes in index.html "

Saving additional versions:

Let's continue making changes and creating commits:

git add .
git commit -m "Added a new style to style.css"

Viewing the commit history:

To see which commits we have made, use:

git log

This will show a list of our commits with their IDs (for example, abc1234).

Return to the previous commit:

If we want to go back to the previous commit, use:

git checkout 

For example:

git checkout abc1234

After that, our project will return to the state saved in that commit.

Return to the current version:

To return to the last commit, run:

git checkout main # or master depending on our main branch

Make a specific commit the main version of the project:

If we want to make the state of our project after working in a certain commit the main version, we will perform the following steps:

  • Switch to the desired commit using the command:
    git checkout abc1234
  • Let's create a new branch from this commit if we want to save the changes:
    git checkout -b new-branch-name
  • Let's make the necessary changes and fix them:
    git add .
    git commit -m "Description of changes"
  • Let's switch to the main branch:
    git checkout main
  • Merge the changes from the new branch into the main branch:
    git merge new-branch-name

This way, we can make the project state saved in a specific commit relevant to the work, while keeping all previous versions in the Git history.

Sample work scenario

The first commit:

We have created a index.html and made a commit with the message "Initial version of the project".

Making changes:

We have changed the index.html and made a commit with the message "Changes in index.html ".

Creating a new version:

We added styles and made a commit, fixing the changes.

Return to the previous version:

We decided that changes to style.css are not necessary, and we want to return to the previous commit. Execute git log, find the commit id and execute git checkout.

Next, we either work with a separate commit, or create a new branch from it (which is a more correct approach) and work in it already. After that, if necessary, we can merge the new branch with the main one.

This way, we can quickly roll back to the desired version of the project in case of unforeseen situations and continue working with the already up-to-date version.

автор - Михаленко Р.
M R. Автор - kaktotak.by Specialization: financial and economic design - modeling of business, investment projects of the real sector, analysis and evaluation of efficiency, optimization of the management decision system.

A wide range of web-based competencies for solving business problems.

Subscribe to my telegram channel - My notes are ECONOMICS +
Improve your quality with me - what, how and why in economics in a simple way. Micro and macro aspects.

And also - WEB Developer's Guide | php+js+seo
Notes and native solutions to simple local tasks in PHP, JS. Something about Laravel, WordPress, Vue and SEO.

  Personal assistance in economic design and web development:

  • Financial and economic modeling, analysis, accounting, business planning
  • Comprehensive web development/project support on the web (php/js, seo – Laravel, WordPress, Vue, telegram, administration, content, advertising in Yandex Direct

  telegram или форма обратной связи

Administrator
4
0
Name
E-mail
Rating
Review

Currency Converter
RUB RUB-icon
USD USD-icon
EUR EUR-icon
CNY CNY-icon
BYN BYN-icon
UAH UAH-icon
KZT KZT-icon
SHORT- what is it about
ECONOMIC LITERACY
  Simple online solutions to problems of economics and finance  
I Want To Know Everything. Useful Tips