Create a dangling commit without checking

Is there a way to quietly create a commit that

  • Not connected to the current branch
  • Not verified after

as

A-B-C-D-E-F-G   # master
       \   \
        X   Y

Where Xand Yare created without notifying the user.

Justification:

I am writing a lot of experimental experiment code and I want to automatically fix the current state when the experiment starts. These intermediate states shouldn't end in my Git story, and I don't want to go through mental overhead before running around all the time (or forgetting about it from time to time).

The idea is to have a lot of dangling commits that won't be transferred to my remote and can be removed by garbage collection. Each individual SHA1 team will be annotated to the results of my experiment, allowing me to track which changes affected the results.

+4
source share
4 answers

If you do

$ git commit -m 'Foo'
[my_branch b54ed59] Foo
$ git reset --hard HEAD^

you will find that the commit you reset has not disappeared, but still exists, so you can do

git checkout b54ed59

and return to this commit by breaking the branch.

A fixation mark allows you to keep it permanently.

+2
source

You can use the command git commit-treeto create a dangling commit.

First, create the files that you want to commit, for example, by executing git add file.

Then create a tree from the index.

git write-tree

stdout. , . , 12345678.

, , , "-" . (git reset HEAD file.)

, .

git commit-tree 12345678 -p HEAD -m "Description"

stdout. HEAD, Description.

, , , GC.

+2

, git commit-tree, : .

git checkout HEAD^{commit}

, , . , , .

+1

:

, , , , . , reflog, .

. , . , , , .

:

origin/master, master dev

:

. , .bashrc. , , , .

1) , :

git add --all
git commit --allow-empty-message -m '' 
<command for running code>

SHA1 , (). , , git log --patch, .

, . .

2) :

git checkout master
git merge --squash dev
git commit -m "<commit message for dev history>"
#fetch & push to origin/master after dealing with any remote issues.

SHA1 .

dev git branch -f dev, , .

This accomplishes your task of handling many commits that will not be popped onto your remote and can be removed by garbage collection (after you are done with them). Each individual SHA1 message can be annotated to the results of your experiment, allowing you to keep track of what changes have affected the results for each moment your code runs. It also allows you to manage versions (locally) of your changes.

0
source

Source: https://habr.com/ru/post/1649304/


All Articles