View Git history before a specific commit ID in the current branch - linux

I'd like some Git log command to list out the commits before some specific commit ID/hash in the current working branch.
E.g. Something like
git log --before <commit id>
But I haven't been able to find what the correct command to do this is.

Just give the commit hash as the ref to explore via log
git log <commitHash>
and it will output all history from that point, backwards, until initial commit.
Alternatively, if you need to exclude this specific commit itself, then refer to its parent with
git log <commitHash>^
Sidenote about your mention of "in the current working branch"
Branches are technically irrelevant here to tree traversal logic. This won't limit output to what's "in" the branch, largely because the common metaphor is quite bad : commits are just not "on" branches. Branches are to be seen as soft (and disposable) shortcuts to designate one commit in the tree.

Related

Can't make a pull request

I have this repository that i forked from another one, and now i need to make a pull request to it, but it says that: "There isn’t anything to compare.", and my commits are not showing:
https://github.com/amorimll/desafio-sharenergy-2023-01
Any help is appreciated, really need this for today.
This is showing in the git rebase:
Short answer
will be checkout to your main branch get the lastest code, then go back to your current working on branch and do git rebase [currentBranchName] main
Explain
so when your create a branch from another branch, is like your created a snapshot code from that branch at that moment. ideally the branch you copied form should prevent make any more changes if possible, until you done working in the new branch and create the PR and done marge it.
what rebase command will do is in case the origin branch had changes, it will pull the latest code form that branch into your working branch first, then to applied any changes you was made for your current working branch. Usually this process will need have some conflict need to fix, if they changed the same file.
Hope this is help you understand :)

Gitlab: How to setup squash on merge?

I want to setup the squash on merge policy in GitLab. This gif showcases exactly what I would like to have:
Merge Strategies
I have set the GitLab merge method to "Fast-forward merge" and the squash commits policy is set to mandatory when merging.
Once merge is done, the git log of the main branch is exactly like I want it. The feature branch commits were squashed and the whole feature appears as one commit in the git log.
Here's the problem:
The squashed commit that is now the head of the main branch has the timestamp of the last commit in the feature branch. I would expect it to be the timestamp of when the fast-forward merge happened (squash). Is there a way to set it up in GitLab?
The merge timestamp is important for me since I need to know when the feature made its way into the main branch. However, I want to keep the commit history streamlined and straightforward, so the default option with an additional merge commit for every merge is something I want to avoid.

How to concat commit messages with GitLab MR squash?

I am using GitLab MR to push commits to my project.
I have a certain template in my commit message that I want to keep on my target branch (e.g. master).
for example:
[Notes]:
when pushing several commits in a single MR we get something like this:
Commit 1: [Notes]: Note1
Commit 2: Merge commit (the one I want to get rid of when squashing)
Commit 3: [Notes]: Note2
when squashing with GitLab MR the squashed commit message is the title of the MR, which prevents me to keep my original commits template.
Is there an option in GitLab setting to change the squashed message to be a concat of all commit messages? similar to interactive rebase in git.
wanted behavior:
Squashed Commit: [Notes]: Note1
Merge commit (the one I want to get rid of when squashing)
[Notes]: Note2
GitLab 14.9.2-ee
I managed to find what I was looking for, it is a GitLab feature introduced in the FREE edition since GitLab 14.6.
Open GitLab website -> Settings -> General -> Merge requests -> Squash commit message template.
Then in the textbox add the following flag:
%{all_commits}
The commit messages are shown in the squash message according to their chronological order.
I do have this checkbox (see attached image) in my merge request enabling me to change the Merge Commit Message but I am using: 15.2.1-ee I'm not sure on what version this got introduced. I think there was a similar functionality in previous versions.

Perforce -Keep working on the project while the code is under review

I am a git person. In git, after I finishing a little feature, I will submit the branch to review and start a new branch to work on new features.
For example, I had submitted a code recview for feature A, and it is still under review. At this time, I want to start working on feature B, assuming feature A's code will be merged in the near future. In Git, typically I just create a new branch to work on the new feature, if there is some problem with feature A I can easily switch back to branch A to fix it and merge the fixed version to my new feature branch.
How's it achieved in perforce? Should I copy the whole code somewhere as a way to manage branch myself?
You can do this in Perforce exactly the same way you'd do it in Git, if you like -- create your feature B branch and work on feature B there. If you need to make changes to your feature A branch, those can be merged back to your mainline and/or your feature B branch.
If you do your code reviews as shelves, you can have any number of them in development at a time; a shelved change is effectively "rebased" onto submitted changes when you sync+resolve.
FWIW, usually the way I've done reviews in Perforce is to make my changes on my own development branch, set up the merge to the mainline, and then shelve that for review. That way I can continue work on my development branch uninterrupted, I don't need to create a new branch, and if there's a fix needed to my merge-in-progress I can just amend the shelved change (either by submitting the fix to my branch and adding it to the merge, or making the edit as part of the merge operation); it also has the benefit of making conflict resolution (if any) part of the change under review.

Target specific commit in gitolite rules

I need to forbid pushing of specific commit (by its sha). Is it possible to do with gitolite configuration?
I tried specifying something like
repo myRepo
- 794b62a8b1cf4417c8320a261177b43bd5d8331e = #all
But it does not work as intended. I guess that VREFs can help here but I din't find much info on that.
You can set in place a VREF which will list commits pushed and reject the push if one of those commits matches the one you want to block.
Check as an example src/VREF/MERGE-CHECK, which does use git rev-list to list commits.
See Adding a VREF to implement and add your own.

Resources