rebase

Git commits are duplicated in the same branch after doing a rebase

此生再无相见时 提交于 2019-11-26 12:35:12
问题 I understand the scenario presented in Pro Git about The Perils of Rebasing. The author basically tells you how to avoid duplicated commits: Do not rebase commits that you have pushed to a public repository. I am going to tell you my particular situation because I think it does not exactly fit the Pro Git scenario and I still end up with duplicated commits. Let\'s say I have two remote branches with their local counterparts: origin/master origin/dev | | master dev All four branches contains

Is there a way to squash a number of commits non-interactively?

 ̄綄美尐妖づ 提交于 2019-11-26 11:51:07
问题 I\'m trying to squash a range of commits - HEAD to HEAD~3. Is there a quick way to do this, or do I need to use rebase --interactive? 回答1: Make sure your working tree is clean, then git reset --soft HEAD~3 git commit -m 'new commit message' 回答2: I personally like wilhelmtell's solution: git reset --soft HEAD~3 git commit -m 'new commit message' However, I made an alias with some error checking so that you can do this: git squash 3 'my commit message' I recommend setting up aliases that

Rebasing and what does one mean by rebasing pushed commits

醉酒当歌 提交于 2019-11-26 11:45:52
问题 It is often said that, you should not rebase commits that you have already pushed. What could be meaning of that? 回答1: The ProGit book has a good explanation. The specific answer to your question can be found in the section titled " The Perils of Rebasing ". A quote from that section: When you rebase stuff, you’re abandoning existing commits and creating new ones that are similar but different. If you push commits somewhere and others pull them down and base work on them, and then you rewrite

Remove folder and its contents from git/GitHub's history

青春壹個敷衍的年華 提交于 2019-11-26 11:26:09
I was working on a repository on my GitHub account and this is a problem I stumbled upon. Node.js project with a folder with a few npm packages installed The packages were in node_modules folder Added that folder to git repository and pushed the code to github (wasn't thinking about the npm part at that time) Realized that you don't really need that folder to be a part of the code Deleted that folder, pushed it At that instance, the size of the total git repo was around 6MB where the actual code (all except that folder) was only around 300 KB . Now what I am looking for in the end is a way to

Rebasing a Git merge commit

假如想象 提交于 2019-11-26 09:15:12
问题 Take the following case: I have some work in a topic branch and now I\'m ready to merge back to master: * eb3b733 3 [master] [origin/master] | * b62cae6 2 [topic] |/ * 38abeae 1 I perform the merge from master, resolve the conflicts and now I have: * 8101fe3 Merge branch \'topic\' [master] |\\ | * b62cae6 2 [topic] * | eb3b733 3 [origin/master] |/ * 38abeae 1 Now, the merge took me some time, so I do another fetch and notice that the remote master branch has new changes: * 8101fe3 Merge

How to rebase one Git repository onto another one?

↘锁芯ラ 提交于 2019-11-26 07:19:11
问题 I had one Git repository (A) which contains the development of a project until a certain point. Then I lost the USB stick this repo A was on. Luckily I had a backup of the latest commit, so I could create a new repository (B) later where I imported the latest project\'s state and continue development. Now I recovered that lost USB stick, so I have two Git repositories. I think I just have to rebase repo B onto repo A somehow, but I have no idea how to do that, maybe using fetch/pull and

git rebase and git push: non-fast forward, why use?

独自空忆成欢 提交于 2019-11-26 06:58:01
问题 I have a branch that should be available to other contributors and that should constantly stay up to date with the master. Unfortunately, every time I do \'git rebase\' and then try to push, it results in \'non-fast forward\' message and abortion of pushing. The only way to push here is to use --force. Does that mean I should use \'git merge\' instead of rebasing if my branch went public and others are working on it? 回答1: A few notes on how git works (non technical): When you rebase, git

Can I make fast forwarding be off by default in git?

不打扰是莪最后的温柔 提交于 2019-11-26 04:56:57
问题 I can\'t really ever think of a time when I would use git merge rather than git rebase and not want to have a commit show up. Is there any way to configure git to have fast forwarding off by default? The fact that there\'s an --ff option would seem to imply that there\'s a way, but I can\'t seem to find it in the documentation. 回答1: Yes, there is --no-ff . You can configure merge options per branch, e.g. git config branch.master.mergeoptions "--no-ff" adds the following to your $(REPO)/.git

Squash the first two commits in Git? [duplicate]

梦想与她 提交于 2019-11-26 04:02:41
问题 This question already has an answer here: Combine the first two commits of a Git repository? 8 answers With git rebase --interactive <commit> you can squash any number of commits together into a single one. That\'s all great unless you want to squash commits into the initial commit. That seems impossible to do. Are there any ways to achieve it? Moderately related: In a related question, I managed to come up with a different approach to the need of squashing against the first commit, which is,

How to squash all git commits into one?

旧时模样 提交于 2019-11-26 03:21:53
问题 How do you squash your entire repository down to the first commit? I can rebase to the first commit, but that would leave me with 2 commits. Is there a way to reference the commit before the first one? 回答1: Perhaps the easiest way is to just create a new repository with current state of the working copy. If you want to keep all the commit messages you could first do git log > original.log and then edit that for your initial commit message in the new repository: rm -rf .git git init git add .