This is the situation, working with Git.

In the project I implemented several classes that handle the notification.

Now it turned out that it is not necessary. But I spent a lot of time on this and would like to keep a copy of what has now turned out ...

How can you save, cut out all that is not necessary, but then if you need so that you can go back?

  • 2
    Make a branch in which you put your changes, where your problems are not clear ... - Makarenko_I_V
  • @Makarenko_I_V yes, but I don’t want to drag myself through this project through the whole project ... I don’t need it to hang all the time ... I thought I could put the tag? - Aleksey Timoshchenko
  • five
    it is possible to put the tag and correctly sign it (so that later it would be clear). And then you can safely delete the changes and continue to code. - KoVadim
  • one
    A tag is exactly one file for 41 bytes (40 bytes hash and newline). - KoVadim
  • 2
    @AlekseyTimoshchenko but there is nothing wrong with a separate branch. In essence, this is just a pointer to a commit. Absolutely lightweight thing - Malov Vladimir

2 answers 2

  1. if your changes remain in the shared repository (i.e., the history will not be rewritten to remove your changes), just remember the hash of your last commit so that you can return to it later:

    1. on the "piece of paper";
    2. creating a pointer to this commit (very β€œlekgovesnaya” operation - only one file of 41 bytes will be created in the storage):

      • either fixed - tag (tag):

        $ git tag имя.ΠΌΠ΅Ρ‚ΠΊΠΈ ΠΊΠΎΠΌΠΌΠΈΡ‚ 

        By the way, until you explicitly specify to send your tags to the shared storage (for example, using the --tags or --all options of the push command), your colleagues will not know about their existence: they will be stored only in your local copy of the storage;

      • or floating - branch (branch):

         $ git branch имя.Π²Π΅Ρ‚ΠΊΠΈ ΠΊΠΎΠΌΠΌΠΈΡ‚ 

        likewise, unless you explicitly send this pointer to the shared storage (for example, using the --all option of the push command, or by specifically mentioning the pointer - git push ΠΎΠ±Ρ‰Π΅Π΅.Ρ…Ρ€Π°Π½ΠΈΠ»ΠΈΡ‰Π΅ имя.Π²Π΅Ρ‚ΠΊΠΈ ), your colleagues will also not know that this pointer exists.

  2. If the changes you have made have not yet been sent to the general repository or will be forcibly removed from it (by rewriting the history), you can create another copy of the repository:

    1. with the working directory (i.e., with all files whose history is being tracked):

       $ git clone /ΠΏΡƒΡ‚ΡŒ/ΠΊ/Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΌΡƒ/Ρ…Ρ€Π°Π½ΠΈΠ»ΠΈΡ‰Ρƒ /ΠΏΡƒΡ‚ΡŒ/ΠΊ/ΠΊΠΎΠΏΠΈΠΈ 
    2. or without a working directory (to save space):

       $ git clone /ΠΏΡƒΡ‚ΡŒ/ΠΊ/Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΌΡƒ/Ρ…Ρ€Π°Π½ΠΈΠ»ΠΈΡ‰Ρƒ /ΠΏΡƒΡ‚ΡŒ/ΠΊ/ΠΊΠΎΠΏΠΈΠΈ --bare 
    3. or even a β€œbundle”:

       $ git bundle create Ρ„Π°ΠΉΠ».с.ΠΏΠ°ΠΊΠ΅Ρ‚ΠΎΠΌ Π½Π°Π±ΠΎΡ€.ΠΊΠΎΠΌΠΌΠΈΡ‚ΠΎΠ² 

and how it will be possible later to use the saved pointer or a copy of the repository - it β€œpulls” to another, not less verbose answer.

  • Well, most of all I like the option with a tag ... Firstly, the branches will not hang, secondly it will be a hint just for me ... But I truly understand that at any moment I can return to this tag as easily as switching from one branches to another? - Aleksey Timoshchenko
  • 2
    both branches (branch) and tags (tag) are pointers to a commit. all the difference between them - the label points to the same commit, and the branch can move as you add commits. - aleksandr barakin
  • perhaps about everything - I bent the stick. there are more differences. but almost all the manipulations that can be done with the branch can be done with the label. - aleksandr barakin
  • The option "on a piece of paper" has a critical drawback - it will not save the commit from the garbage collector. - Pavel Mayorov
  • @PavelMayorov, like it was an option for the case when there is a commit in history, and not when it is somewhere in a parallel branch that was deleted. Although you could clearly indicate this in the answer. - Qwertiy ♦

In my opinion, in such cases a fork is made and a new repository is maintained, classes are being finalized to become a library, isolated from strong links with the project . Thus we get a full-fledged library in the piggy bank.

Of course, you need to do this if it is cheap to do otherwise, you should use the tag - but in large repositories, you can litter the repository itself and lose the tag when you clean up the old tags. The same with the branches. If the development goes through git flow, then there will be only 2 permanent branches, the rest will be demolished after the implementation of features.

ps In the gita, you need to get used to the fact that the tags are lightweight, the branches are lightweight, that you do not need to be afraid of merge and you do not need to be afraid of forks. Repository management systems like github, gitlab, bitbucket are designed for all this, including forks