Git: the cover-up alternative

I am using Git Extensions for my projects. I really like it. There is an issue that is keeping me eavesdropping and I'm sure there is a trick in the Git Extensions for it. Here's the script:

  • From the main branch, I created 3 branches A

    , B

    and C

    .
  • Started working on a branch A

    , made some changes
  • Switching to branch B

    I can still see the changes made in A

    as they are not being executed
    • I don't want to commit the changes to A

      , because I haven't finished yet and I don't want this message to appear in the commit history
    • I dont want to write changes to A

      , because if I make changes to B

      and switch to C

      , I need to write changes to B

      too ==> changes to A

      gone: overridden by the new type.

Can I make many delays in different branches?
If not, what is the alternative for stash

?
It is there commit

and revert

commit

my only option here?

+3


source to share


2 answers


git worktree

The git worktree was introduced in 2007 in a folder contrib

in the git repository and has been called new-workdir

.


eg:

git worktree add <second path>

      

will create another folder on your computer that will allow you to work on different branches at the same time.

git worktree

will create two separate working folders, separated from each other, pointing to the same repository.

This will allow you to perform any experiments on a new workstation without affecting the repository in any way. In the attached image, you can see that there are 2 separate working folder , but they both share the same repo and share content.

Here's an example of how to create a new working line and what is the result:



enter image description here


Can I make many delays in different branches?

Yes, but you can avoid it. You can float to different branches than the one you originally laid out in sources.

If not, what is the alternative to a wallet?

As explained above - use worktree

Is commit and uncommit my only option here?

Again: as above - use worktree

+4


source


You can track your stamps and apply them in any order. While on a branch, A

type:

git stash save "stash_a"

      

Similarly, you can specify stamps from the branches B

and C

. You can list all the stamps by typing

git stash list

      

To apply a specific stash, you can use

git stash pop stash@{n}

      

where n

is the wallet index. Use the names you provided to copy the bindings at their respective indices on the stack.



You mentioned the following:

I don't want to commit the changes to A because I am not finished yet and I don't want this commit to show up in the commit history.

In fact, there is nothing wrong with committing, because you can change this message at any time without any consequences, assuming you either haven't pushed, or if you pushed that the branch is not in use. So an alternative to using git stash

on a branch A

would be to simply do this:

git commit -m 'WIP'

      

Then, when you go back to the branch A

and complete the task, do the following:

git commit --amend

      

Note that execution git stash

actually creates 2 (or sometimes 3) objects under the hood. Thus, both methods I described rely on committing in some way. The work line answer given by @CodeWizard can be an alternative to using commits.

+1


source







All Articles