programing

git add, commit 및 push 명령을 하나로?

new-time 2020. 5. 10. 12:34
반응형

git add, commit 및 push 명령을 하나로?


이 세 가지 명령을 하나로 사용할 수있는 방법이 있습니까?

git add .
git commit -a -m "commit" (do not need commit message either)
git push

때로는 하나의 문자, CSS 패딩 또는 무언가 만 변경하고 있습니다. 여전히 변경 사항을 적용하려면 세 가지 명령을 모두 작성해야합니다. 내가 하나의 푸셔 인 많은 프로젝트가 있으므로이 명령은 훌륭합니다!


@Gavin의 답변을 바탕으로 :별명 대신 lazygit을 함수로 만들면 인수를 전달할 수 있습니다. 내 .bashrc (또는 Mac의 경우 .bash_profile)에 다음을 추가했습니다.

function lazygit() {
    git add .
    git commit -a -m "$1"
    git push
}

이를 통해 다음과 같은 커밋 메시지를 제공 할 수 있습니다.

lazygit "My commit msg"

물론 어느 먼 곳으로 가야하는지 또는 어떤 지사와 같은 더 많은 논증을 받아들임으로써 이것을 더욱 강화할 수 있습니다.


 

.gitconfig

파일에 별칭을 추가했습니다 .

[alias]
    cmp = "!f() { git add -A && git commit -m \"$@\" && git push; }; f"

용법:

git cmp "Long commit message goes here"

모든 파일을 추가 한 다음 커밋 메시지에 주석을 사용하여 원래 위치로 푸시합니다.커밋 메시지가 무엇인지 제어 할 수 있기 때문에 더 나은 솔루션이라고 생각합니다.별명은 명령 행에서 정의 할 수도 있습니다. 그러면 별명이 다음에 추가됩니다

.gitconfig

.

git config --global alias.cmp '!f() { git add -A && git commit -m "$@" && git push; }; f'

웨인 베르너 (Wayne Werner)는 그의 의구심에 대해 동의하지만, 이것은 기술적으로 선택 사항입니다.

git config alias.acp '! git commit -a -m "commit" && git push'

별칭을 정의하는 것을 실행

commit

하고

push

. 로 사용하십시오

git acp

. 이러한 "쉘"별명은 항상 git 저장소의 루트에서 실행됩니다.다른 옵션은 푸시를 수행하는 커밋 후 후크를 작성하는 것입니다.


git이 설계된 워크 플로를 오해 할 수 있다고 생각합니다. (댓글에서 의미하는 바를 명확히 / 수정하기 위해 , 파일이 이미 추가 된 경우 아직 준비되지 않은 변경 사항을 추가하는 것과 같은 목적을 수행

git add .

하므로) 가 필요하지 않습니다.

commit -a

일반적으로 다음과 같은 작업을 수행합니다.

# make some changes
$ git commit -a -m "Changed something"
# make some more changes
$ git commit -a -m "Changed something else"

세척, 헹굼, 반복, 기능 X가 끝났을 때, 또는 멈추는 지점에있을 때까지 또는 다른 사람들이 자신이 한 일을보고 싶어 할 때까지. 그런 다음에

$ git push

Git은 SVN이 아니지만 그렇게 사용하려고합니다. 당신은 문서의 끝 부분에 자원의 일부를 찾을 수 있습니다

여기에

몇 가지 유용 할 수 있습니다.


나는 이것을 .bash_profile에서 사용한다

gitpush() {
    git add .
    git commit -m "$*"
    git push
}
alias gp=gitpush

그것은 다음과 같이 실행됩니다

gp A really long commit message

 

source ~/.bash_profile

별명을 저장 한 후 실행하는 것을 잊지 마십시오 .


bash script를 사용하고 alias를 설정하여 모든 명령 또는 명령 그룹을 시작할 수 있습니다

git commit -am "your message" && git push 

bash에서 별명으로 설정하십시오.

$ alias lazygit="git add .; git commit -a -m '...'; git push;";

불러라:

$ lazygit

이 별칭을 영구적으로 만들려면 .bashrc 또는 .bash_profile에 별칭을 포함시켜야합니다.


가장 간단한 해결책은 다음과 같습니다.

git commit -a -m "commit" && git push

git add

커밋의 -a 매개 변수에 이미 포함되어 있지만 원하는 경우 모두 연결할 수 있습니다.

git add . && git commit -a -m "commit" && git push

In Linux/Mac, this much practical option should also work

git commit -am "IssueNumberIAmWorkingOn --hit Enter key
> A detail here --Enter
> Another detail here --Enter
> Third line here" && git push --last Enter and it will be there

If you are working on a new branch created locally, change the git push piece with git push -u origin branch_name

If you want to edit your commit message in system editor then

git commit -a && git push 

will open the editor and once you save the message it will also push it.


You can try gitu.

For the first time (node js has to be installed):

npm install -g git-upload

After that:

gitu COMMIT_MSG

To issue those three commands at once.

The good thing is that you don't have to worry when you reinstall your system or when you want to do this on different computers and No file modification is needed. This also work on different platforms (not just Linux and Mac, but also Windows under command prompt like cmd and powershell) just that you have to install npm and nodejs (git of course).


If the file is already being tracked then you do not need to run git add, you can simply write git commit -am 'your message'

If you do not want to write a commit message you might consider doing something like

git commit --allow-empty-message -am ''


As mentioned in this answer, you can create a git alias and assign a set of commands for it. In this case, it would be:

git config --global alias.add-com-push '!git add . && git commit -a -m "commit" && git push'

and use it with

git add-com-push

I use a batch file:

@ECHO OFF
SET /p comment=Comment:
git add *
git commit -a -m "%comment%"
git push

Write a small script named gitpush.sh with below lines and add it your ~ directory.

echo $1
git add .
git commit -m "$1"
git push

Now add an alias in ~/.bashrc like below :

alias gitpush='~/gitpush'

Now from any git repository just write gitpush "message" .


There are some issues with the scripts above:

shift "removes" the parameter $1, otherwise, "push" will read it and "misunderstand it".

My tip :

git config --global alias.acpp '!git add -A && branchatu="$(git symbolic-ref HEAD 2>/dev/null)" && branchatu=${branchatu##refs/heads/} && git commit -m "$1" && shift && git pull -u origin $branchatu && git push -u origin $branchatu'


When you want svn-like behavior of git commit, use this in your git aliases in your .gitconfig

commit = "!f() { git commit \"$@\" && git push; };f"


If you're using fish shell (building off of btse's answer):

Save this file within '~/.config/fish/functions' as 'quickgit.fish'. Create the directory if it does not exist. '--git-dir=$PWD/.git' Ensures that we run the git commands against the git project where we called the function

function quickgit # This is the function name and command we call
    git --git-dir=$PWD/.git add . # Stage all unstaged files
    git --git-dir=$PWD/.git commit -a -m $argv # Commit files with the given argument as the commit message
    git --git-dir=$PWD/.git push # Push to remote
end

Restart terminal, navigate to project, make changes, and now you can call 'quickgit "example message"'. Changes will now be added, committed, and push :).

Also can be found as a Gist here: https://gist.github.com/Abushawish/3440a6087c212bd67ce1e93f8d283a69


There are plenty of good solutions already, but here's a solution that I find more elegant for the way I want to work:

I put a script in my path called "git-put" that contains:

#!/bin/bash
git commit "$@" && git push -u

That allows me to run:

git put -am"my commit message"

..to add all files, commit them, and push them.

(I also added the "-u" because I like to do this anyway, even though it's not related to this issue. It ensures that the upstream branch is always set up for pulling.)

I like this approach because it also allows to to use "git put" without adding all the files (skip the "-a"), or with any other options I might want to pass to commit. Also, "put" is a short portmanteau of "push" and "commit"


This Result - Try this: Simple script one command for git add, git commit and git push

Open your CMD on Windows and paste this answer

git commit -m "your message" . && git push origin master

This example my picture screenshot : https://i.stack.imgur.com/2IZDe.jpg


I did this .sh script for command

#!/bin/sh
cd LOCALDIRECTORYNAME/  
git config --global user.email "YOURMAILADDRESS"
git config --global user.name "YOURUSERNAME"
git init
git status
git add -A && git commit -m "MASSAGEFORCOMMITS"
git push origin master

Since the question doesn't specify which shell, here's the eshell version based on the earlier answers. This goes in the eshell alias file, which might be in ~/.emacs.d/eshell/alias I've added the first part z https://github.com/rupa/z/ which let's you quickly cd to a directory, so that this can be run no matter what your current directory is.

alias census z cens; git add .; git commit -m "fast"; git push

Add in ~/.bash_profile for adding, committing and pushing with one command put:

function g() { git commit -a -m "$*"; git push; }

Usage:

g your commit message
g your commit message 'message'

No quotes are needed although you can't use semicolons or parenthesis in your commit messages (single quotes are allowed). If you want to any of these just simply put double quotes in you message, e.g.:

g "your commit message; (message)"

To create a comment in your message do:

g "your commit message:
> your note"

There's also a function for adding and committing in a similar way:

function c() { git add --all; git commit -m "$*"; }

Works exactly the same way that g function and has the same constraints. Just put c instead. E.g.

c your commit message

You can also add an alias for pushing to the remote:

alias p='git push'

Usage:

p

That amounts into 2 letters, c and p you use while working with your git repository. Or you can use g instead to do it all with only one letter.

Full list of aliases and functions: https://gist.github.com/matt360/0c5765d6f0579a5aa74641bc47ae50ac


Building off the lazygit answer, the following solution adds a user check to verify the changes before pushing. It will revert the commands if cancelled. And all that will happen if and only if there are changes in the local repo.

### SAFER LAZY GIT
function lazygit() {
  git add .
  if git commit -a -m "$1"; then
    read -r -p "Are you sure you want to push these changes? [y/N]} " response
    case "$response" in
      [yY][eE][sS]|[yY])
        git push
        ;;
      *)
        git reset HEAD~1 --soft
        echo "Reverted changes."
        ;;
    esac
  fi
}

This is perfect for command grouping.

Grouping Commands

{ list; } Placing a list of commands between curly braces causes the list to be executed in the current shell context. No subshell is created. The semicolon (or newline) following list is required.

legit(){ git add --all; git commit -m "$1"; git push origin master; }
legit 'your commit message here'

I like to run the following:

git commit -am "message";git push

I found this yolo alias to be amazing to even submit a random comment to the commit while I am being lazy. It works really well out of the box, so I just do git yolo and all my changes are pushed automatically.

참고URL : https://stackoverflow.com/questions/19595067/git-add-commit-and-push-commands-in-one

반응형