English 中文(简体)
我怎么会把我的最后一位N承诺混在一起呢?
原标题:How do I squash my last N commits together?

我怎样把我最后的N国言混为一谈。

最佳回答
问题回答

You can do this fairly easily without git rebase or git merge --squash. In this example, we ll squash the last 3 commits.

If you want to write the new commit message from scratch, this suffices:

git reset --soft HEAD~3 &&
git commit

如果你想开始编辑新的承诺信息,并对现有承诺信息进行分类(即类似于“ pick/ash”/.../squashgit rebase-i 指示清单,则你需要提取这些信息,并将之通过<>条/代码>:

git reset --soft HEAD~3 && 
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"

Both of those methods squash the last three commits into a single new commit in the same way. The soft reset just re-points HEAD to the last commit that you do not want to squash. Neither the index nor the working tree are touched by the soft reset, leaving the index in the desired state for your new commit (i.e. it already has all the changes from the commits that you are about to “throw away”).

http://www.ohchr.org。

git reset --soft HEAD~2 
git commit -m "new commit message"
git push -f

2 即最后两项承诺将兑现。 页: 1

我建议尽可能避免<条码>(git reset>)——特别是对于Gite-novices。 除非你真的需要根据承诺的 > /m>使程序自动化,否则会采取不太宽松的办法......

  1. Put the to-be-squashed commits on a working branch (if they aren t already) -- use gitk for this
  2. Check out the target branch (e.g. master )
  3. git merge --squash (working branch name)
  4. git commit

The commit message will be prepopulated based on the squash.

感谢。 我发现,你可以利用这一指挥来掩盖最后3项承诺:

git rebase -i HEAD~3

This is handy as it works even when you are on a local branch with no tracking information/remote repo.

指挥部将开设互动数据库编辑,然后按照正常情况重新排列顺序、打字、改写。


www.un.org/Depts/DGACM/index_spanish.htm 利用互动数据库编辑:

互动数据库编辑显示了最后三项承诺。 这一限制由<代码>HEAD~3确定。 指挥系统<代码>git rebase -i HEAD~3。

最新承诺(HEAD)首先在线上展示。 1. 从<代码>#开始的行文为评论/文件。

所展示的文件相当清楚。 在任何特定线路上,你可以把指挥从<条码>pick改为你选择的指挥。

I prefer to use the command fixup as this "squashes" the commit s changes into the commit on the line above and discards the commit s message.

As the commit on line 1 is HEAD, in most cases you would leave this as pick. You cannot use squash or fixup as there is no other commit to squash the commit into.

你也可以改变承诺的次序。 这使得你能够qu清或固定不相邻的承诺。

“interactive


A practical everyday example

我最近承诺了一个新特点。 从那时起,我已承付两套保.。 但是,现在我发现,在我所承诺的新特点中,出现了一种 b(或可能只是一种拼错)。 怎么说! 我不想再作一次新的行动,对我的承诺历史进行投票!

我所做的第一件事是纠正错误,并对评论<条码>作出新的承诺,将这一条纳入我的新特点!

然后,我操作<代码>gitlog或gitk,并获取新的特征(此处为1ff9460)。

其次,我召集互动式数据库编辑<代码>git rebase-i 1ff9460~。 <代码>~ 之后,SHA告知编辑,将承诺列入编辑。

其次,我把含有固定装置(fe7f1e0)的承诺移至该特征的后面,并将<代码>pick/code>改为upfix

在关闭编辑时,固定装置将渗入主物,我的承诺历史将看清冰和干净!

如果所有承诺都是地方性的,但如果你试图改变已经推向遥远的人们的任何承诺,就会真正给已经检查同一部门的其他发展中国家造成问题!

“enterography

Here is another visual example of what would follow after executing: git rebase -i HEAD~3

“Here,

Source: https://www.git-tower.com/learn/git/faq/git-squash/

If you use TortoiseGit, you can the function Combine to one commit:

  1. Open TortoiseGit context menu
  2. Select Show Log
  3. Mark the relevant commits in the log view
  4. Select Combine to one commit from the context menu

This function automatically executes all necessary single git steps. Unfortunatly only available for Windows.

很多答复是以<代码>git rebase的指令为依据的,但从我的经验来看,这一指示有些复杂,而且对于gin子来说也有些先进。

让我说,你想要 last过去3年的承诺。 然后是:

  • Note down current commit id: Use git log -1 --oneline and note the commit-id of the present state (just in case you do something wrong with git reset)
  • Go back 3 commits: Using git reset --soft HEAD~3 you ll go back 3 commits (and sort of forget that you ve had made these three commits earlier)
  • Do a new commit: Now simply do git commit -m <NEW_SINGLE_MESSAGE> which will automatically combine the three commits under your message

如果有点燃错误的话,你可以再次通过<条码>git reset --soft <ORIGINAL_COMMIT>回到原来的状态。

,Anomies accreditation/a> 是好的,但我感到对此事不安全,因此我决定添加一 couple屏幕。

Step 0: git log

gitlog。 最重要的是,发现首项承诺中的 has子希望qu。 只有:

“entergraph

Step 1: git rebase

具体如下:

$ git rebase -i 2d23ea524936e612fae1ac63c95b705db44d937d

Step 2: pick / squash what you want

就我而言,我要把首次作出的承诺推上一切。 顺序从头到最后,这正是<编码>git 日志/代码>中的其他方式。 就我而言,我想:

enter image description here

Step 3: Adjust message(s)

如果你只挑出一件事, rest掉其余部分,你可以调整一个承诺信息:

enter image description here

That s it. Once you save this (:wq), you re done. Have a look at it with git log.

我认为,这样做最容易的方式是,根据主人翁精神和做“<条码>合并——Squash

git checkout master
git checkout -b feature_branch_squashed
git merge --squash feature_branch

Then you have all of the changes ready to commit.

Procedure 1

(1) 查明承诺的短 hash

# git log --pretty=oneline --abbrev-commit
abcd1234 Update to Fix for issue B
cdababcd Fix issue B
deab3412 Fix issue A
....

www.un.org/spanish/ecosoc 也可以用来获取短 has。

(2) 如果你想qu(合并)最后两件承诺

# git rebase -i deab3412 

3) 该编码为nano的编辑。 页: 1

....
pick cdababcd Fix issue B
pick abcd1234 Update to Fix for issue B
....

4) 将<代码>pick改为squash 页: 1 在重新命名之后,它就好像如下。

....
pick cdababcd Fix issue B
squash abcd1234 Update to Fix for issue B
....

5) 现在节省并关闭<代码>nano编辑。 Press ctrl + o and press Enter to Save. 之后,报章<代码>ctrl + x 退出编辑。

然后,nano的编辑再次开放,必要时更新评论意见。

7) Now its squashed successfully, you can verify it by checking logs.

# git log --pretty=oneline --abbrev-commit
1122abcd Fix issue B
deab3412 Fix issue A
....

8) 如今,我们开始重新发起。 添加<代码>+在分支名称前签字。 这意味着强迫推进。

# git push origin +master

注: 依据的是<代码>ubuntu。 如果你使用不同的斜体(Windows/code>或Mac),那么除编辑外,上面的指令相同。 你可能会有不同的编辑。

Procedure 2

  1. First add the required files for commit
git add <files>
  1. Then commit using --fixup option and the OLDCOMMIT should be on which we need to merge(squash) this commit.
git commit --fixup=OLDCOMMIT

现在,这在欧洲开发协会的顶端产生了一项新的承诺,其编号为fixup1 <OLDCOMMIT_MSG>

  1. Then execute below command to merge(squash) the new commit to the OLDCOMMIT.
git rebase --interactive --autosquash OLDCOMMIT^

Here ^ means the previous commit to OLDCOMMIT. This rebase command opens interactive window on a editor (vim or nano) on that we no need to do anything just save and exiting is sufficient. Because the option passed to this will automatically move the latest commit to next to old commit and change the operation to fixup (equivalent to squash). Then rebase continues and finishes.

Procedure 3

  1. If need to add new changes to the last commit means --amend can be used with git-commit.
    # git log --pretty=oneline --abbrev-commit
    cdababcd Fix issue B
    deab3412 Fix issue A
    ....
    # git add <files> # New changes
    # git commit --amend
    # git log --pretty=oneline --abbrev-commit
    1d4ab2e1 Fix issue B
    deab3412 Fix issue A
    ....  

-amend 将最新承诺的新改动合并为<代码>dababcd,并产生新的承诺编号:1d4ab2e1

Conclusion

  • Advantage of 1st procedure is to squash multiple commits and to reorder. But this procedure will be difficult if we need to merge a fix to very old commit.
  • So the 2nd procedure helps to merge the commit to very old commit easily.
  • And the 3rd procedure is useful in a case to squash a new changes to last commit.

举例来说,如果你想要将最后3项承诺分成一个分支(即:https://bitbucket.org

我所做的是

  1. git reset --soft HEAD~3
  2. git commit
  3. git push origin <branch_name> --force

如果你处于一个遥远的分支(所谓的feature-branch),由金库保存(golden_repo_name),那么,这里就把你的承诺推向一个方面:

  1. Checkout the golden repo

    git checkout golden_repo_name
    
  2. Create a new branch from it(golden repo) as follows

    git checkout -b dev-branch
    
  3. Squash与你的地方分支机构合并,你已经这样做。

    git merge --squash feature-branch
    
  4. Commit your changes (this will be the only commit that goes in dev-branch)

    git commit -m "My feature complete"
    
  5. 向贵处地方储存库保住处

    git push origin dev-branch
    

兑现最后10项承诺:

git reset --soft HEAD~10 && git commit -m "squashed commit"

如果你也希望更新边远处,并兑现承诺:

git push -f

任何人都提到在<>IntelliJ上做些什么容易。 IDEA UI:

  • Go to git window
  • Manually select all the commits you want to merge into one.
  • Right-click > Squash Commits > Edit the squashed commit message
  • Click on branch name on left side > Right-click > Push > Force Push

“entergraph

What can be really convenient:
Find the commit hash you want to squash on top of, say d43e15.

现在使用

git reset d43e15
git commit -am  new commit name 

如果你作出许多承诺,<>

<代码>git rebase -i Master, 然后发布键盘,一到编辑

你们会看到这一点:

pick etc1
pick etc2
pick etc2

改为 f _esc y :wq

pick etc1 //this commit will the one commit
f etc2
f etc2

指挥

git push origin +head

method 2 if you have few commits you can do this to delete a commit, you need to do same for delete your second commit and so on

git reset --soft HEAD^1 // or git reset --soft head~1
git commit --amend //then press `:wq` 
git push -f

如果你已经作出承诺,你有意再提出另一承诺,则<>方法3<>

git add files...
git commit --amend  //then press `:wq`
git push origin +head

simple solution:

www.un.org/Depts/DGACM/index_spanish.htm

www.un.org/Depts/DGACM/index_french.htm

如果你想要打上every,就承诺作出单一承诺(例如,首次公开公布项目),则试图:

git checkout --orphan <new-branch>
git commit

这是一种超高温,但是一种冷却的方式,因此,我只是把它 into入ring子:

GIT_EDITOR= f() { if [ "$(basename $1)" = "git-rebase-todo" ]; then sed -i "2,$s/pick/squash/" $1; else vim $1; fi }; f  git rebase -i foo~5 foo

翻译:提供新的“编辑”,如果要编辑的档案名称为git-rebase-todo(互动性数据库迅速)除第一个“pick”改为“squash”,否则就会引人振动——这样,当你催复时,你就会发现 s的承付信息。 (显然,我qu上了最后五项承诺,但你可以改变,不管你喜欢。)

不过,我可能做的是

鉴于你目前是你想要qu的分支部门,总经理是该处的,最新承诺载有承诺的信息,并作者希望使用:

git reset --soft $(git merge-base HEAD master) && git commit --reuse-message=HEAD@{1}

⚠️ WARNING: "My last X commits" might be ambiguous.

  (MASTER)  
Fleetwood Mac            Fritz
      ║                    ║
  Add Danny  Lindsey     Stevie       
    Kirwan  Buckingham    Nicks                                              
      ║         ╚═══╦══════╝     
Add Christine       ║          
   Perfect      Buckingham
      ║           Nicks            
    LA1974══════════╝                                    
      ║                  
      ║                  
    Bill <══════ YOU ARE EDITING HERE
  Clinton        (CHECKED OUT, CURRENT WORKING DIRECTORY)              

https://github.com/fleetwood-mac/band-history/about-our-band-starting-1967.md#i-cant-believe-you- actual-clicked-this”rel=“noreferer” 存放者已提出拉动要求,要求把比尔·克林顿承诺纳入原始文书(<条码>MASTER)。 Primwood Mac承付。

You opened a pull request and on GitHub you see this:

四项承诺:

  • Add Danny Kirwan
  • Add Christine Perfect
  • LA1974
  • Bill Clinton

想没有人会想读一下完整的保存历史。 (实际上是一个存放处,点击上述链接!) 你决定兑现这些承诺。 因此,你去并操作<条码>git reset-soft HEAD~4 && git Rat/code>。 接着,请<代码>git 推介 -force,将其贴在Gite Hub,以清理您的PR。

情况如何? 你刚刚作出从弗里茨到比尔·克林顿的单一承诺。 因为你想到,昨天你正在制作该项目的Buckingham Nicks版本。 。 这与你在Gite Hub中看到的情况相吻合。

? MORAL OF THE STORY

  1. Find the exact files you want to get to, and git checkout them
  2. Find the exact prior commit you want to keep in history, and git reset --soft that
  3. Make a git commit that warps directly from the from to the to

If you don t care about the commit messages of the in-between commits, you can use

git reset --mixed <commit-hash-into-which-you-want-to-squash>
git commit -a --amend

如果你重新与GiteLab合作,你就可以在Merge请求中点击Squash的选择,如下文所示。 承诺的电文为“Mege Request”。

“在座的影像描述”/</a





相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签